-
Notifications
You must be signed in to change notification settings - Fork 690
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
Use Workers to do tile decompression and unpremultiply #9208
Conversation
Thanks for opening this pull request! Things that will help get your PR across the finish line:
|
3430ea8
to
f6b9b8e
Compare
f6b9b8e
to
c6f8206
Compare
672568b
to
823be3a
Compare
823be3a
to
55f1a41
Compare
lastMask = data[rleMaskOffset++]; | ||
} | ||
if (!(lastMask & bitToCheck)) { | ||
this.lastPixel.set(data.subarray(pixSrc, pixSrc+4)) |
Check notice
Code scanning / CodeQL
Semicolon insertion Note
the enclosing function
break; | ||
|
||
default: | ||
console.error('Unrecognised preprocessor message', e); |
Check warning
Code scanning / CodeQL
Log injection Medium
user-provided value
var keyframeBufferSize = 0; | ||
var keyframeBuffer; | ||
|
||
function onMessage(e) { |
Check warning
Code scanning / CodeQL
Missing origin verification in `postMessage` handler Medium
Pre-allocate decompression buffers and use a Worker to decompress and unpremultiply tile data asynchronously while avoiding memory allocation/ deallocation thrashing. Signed-off-by: Chris Lord <[email protected]> Change-Id: I2282e3df8bf40bdc3a2381880d46df33f2451758
55f1a41
to
89d69cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - this needs more work; I don't think we can merge it as-is I'm afraid.
|
||
if ('undefined' === typeof window) { | ||
importScripts('../../node_modules/fzstd/umd/index.js'); | ||
importScripts('../layer/tile/CanvasTileUtils.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect that this has not been tested with a bundlified product build (?) or do we distribute CanvasTileUtils.js on its own ?
if (alpha === 0) { | ||
data.fill(0, i, i + 3); | ||
} else if (alpha !== 255) { | ||
data[i] = Math.ceil((data[i] * 255) / alpha); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use a 64k byte lookup table here as some of the core LibreOffice code does =)
lastMask = data[rleMaskOffset++]; | ||
} | ||
if (!(lastMask & bitToCheck)) { | ||
this.lastPixel.set(data.subarray(pixSrc, pixSrc + 4)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we decided that subarray was unfeasibly slow on firefox, and we didn't want to over-use it ?
@@ -459,7 +484,14 @@ app.definitions.Socket = L.Class.extend({ | |||
// process so - slurp and then emit at idle - its faster to delay! | |||
_slurpMessage: function(e) { | |||
this._extractTextImg(e); | |||
if (e.image && e.image.rawData && this._worker) { | |||
this._queueWorkerTileProcessing(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I reading this right that we take 'tile:' messages only - and we potentially then emit them out of order with subsequent 'delta:' and 'update:' messages which could arrive before the tiles are de-compressed by the thread - that is likely to lead to corrupted pixels.
Hmm.
I'm going to close this as I have a newer, better version of the patch in a different branch. I'll likely need advice resolving some of these comments - I'll try to flag these issues explicitly. |
Summary
Two patches; the first fixes a bug where if we receive new keyframe tiledata and need to ensure the canvas, we end up decompressing/unpremultiplying/putting the old data unnecessarily (I think). The second uses a worker to offload the majority of tile image data decompression and unpremultiplying from the main thread and improves response during large update operations (such as scrolling through a document).
The code is not properly formatted yet, I'm opening this PR now and will update it with fixes once I figure out what those fixes are...
Checklist
make check
make run
and manually verified that everything looks okay