Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Display.imageData() #28

Open
fengb opened this issue Sep 11, 2019 · 3 comments
Open

Optimize Display.imageData() #28

fengb opened this issue Sep 11, 2019 · 3 comments

Comments

@fengb
Copy link
Owner

fengb commented Sep 11, 2019

The pixel translation is actually a pretty strong bottleneck — 33% of execution time.

Thoughts:

  1. Mutate canvas directly — is this possible?
  2. WebWorker
  3. Separate wasm for translation — might not be efficient to copy the data around
@fengb
Copy link
Owner Author

fengb commented Dec 12, 2019

This should be deferred until after GBC support since that will have a radically different layout for pixel values.

Edit: this change has been applied so we can optimize now!

@fengb fengb added this to the 2.0 — GBC milestone Dec 12, 2019
@fengb
Copy link
Owner Author

fengb commented Apr 22, 2020

LLVM gives us this output: https://godbolt.org/z/YXLf4D. Translated to Javascript:

function foo(r0) {
  var r1 = 255;
  var r2 = r0 & 992;
  r1 = r1 & (r0 << 3);
  r0 = r0 & 31744;
  r1 = r1 | (r2 << 6);
  r0 = r1 | (r0 << 9);
  r0 = r0 | -16777216;
  return r0;
}

function simplified(raw) {
  var r0 = 31744 & raw;
  var r1 = 255 & (raw << 3);
  var r2 = 992 & raw;

  return -16777216 | (r0 << 9) | r1 | (r2 << 6);
}

@fengb
Copy link
Owner Author

fengb commented Apr 23, 2020

Applying the LLVM voodoo led to 10-20% performance boost: f29bca4#diff-c2b923b8185dd06e822dec6c545dae85R100

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant