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
fix: move blurhash worker operations to before status rendering #1391
Conversation
src/routes/_utils/blurhash.js
Outdated
init() | ||
// TODO: should maintain a cache outside of worker to avoid round-trip for cached data | ||
const { encoded, decoded, imageData } = await worker.postMessage(blurhash) | ||
if (encoded !== blurhash) { // TODO: why do we check this? Shouldn't it always be the same? |
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.
@sorin-davidoi I didn't catch this in the last PR, but do you know why we need to pass the encoded string into the worker, have the worker return it, and then check that it's exactly the same as the value we already gave it? Am I missing something?
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.
Because we are listening for all messages posted by the Web Worker, so we might also get decodings meant for other media
.
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.
Ahhh, understood. I think now that we're using promise-worker
, we should be safe. It keeps track of all messages using an internal autoincrementing ID, so we won't get the wrong message (as long as all worker interactions are routed through promise-worker
).
Huh, I'm looking at Chrome tracing, and it's really unclear to me why there's such a long delay waiting for the worker to return the message. It looks like just pure idle time. Something about |
Stopped sending the encoded data back and forth from the worker, and moved the cache outside of the worker to avoid round-trips. |
9acdcf3
to
1db1f69
Compare
Hm, it seems that the OffscreenCanvas approach is just way slower in Chrome. I'm getting ~600ms for the total time to decode a blurhash, as opposed to ~15ms in Firefox. When I switch Chrome to not use OffscreenCanvas, it starts taking 20-100ms in Chrome. Can't tell if the problem is OffscreenCanvas, or creating a blob URL in a worker, or what. |
So it turns out that |
Odd, I tried creating a new OffscreenCanvas every time instead of reusing the same one, but the perf doesn't change. 800ms or so. Maybe this is just a Linux thing; I need to test more. |
Hm, OffscreenCanvas is slow on Chrome for Android as well - between 700ms and 1.2s. Not sure if we can use this API right now |
As described in #1381 (comment) I would like to avoid the "pop" where the blurhash suddenly shows after the worker is done decoding it. This moves blurhash decoding into the same point in time when we asynchronously fetch status data from IndexedDB or the cache, so it happens before status rendering.
Other changes:
init()
of worker a bit earlierI'm still dissatisfied with the worker round-trip time (on my local Chrome desktop it seems to take like a few hundred milliseconds... is that normal? is it just a dev tools artifact?). Also I'd like to move the cache away from the worker if we can't fix that round-trip time.