Closed Bug 1640292 Opened 4 months ago Closed 4 months ago

Move RemoteSettingsWorker.checkContentHash from worker to main thread

Categories

(Firefox :: Remote Settings Client, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
Firefox 78
Tracking Status
firefox78 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

The attachment downloader relies on RemoteSettingsWorker.checkContentHash to check the integrity of an ArrayBuffer. This is implemented by posting the data to a worker thread, using the web crypto API to compute the hash and then posting the result back.

The web crypto API already uses a thread pool, so there is no benefit from passing the buffer to a separate worker thread before computing the digest.

Let's do the check from the main thread instead:

  • In the best case, when the sizes don't match, there is almost no cost of running the check on the main thread.
  • In the worst case, when the hash has to be computed, the crypto API will process the data on a separate thread, which is not more expensive than passing the data to a separate thread first.

Linking to bug 1508332 for visibility. Both bugs share the same goal (improving performance), but do so in a different way: the other bug suggests to move operations to a worker thread, whereas this bug is about moving an operation from the worker thread to the main thread.

The work in this bug does not preclude the work in bug 1508332 ; it is possible to move this function together with all of its callers to a worker thread. This bug is just concerned with ensuring that checksum calculation happens on the same thread as where the data was read.

Blocks: 1508332

The crypto API does most of its work on the background thread. There is
no benefit in posting the buffer to a worker thread.

Pushed by rob@robwu.nl:
https://hg.mozilla.org/integration/autoland/rev/ddc560ee9d02
Move RemoteSettingsWorker.checkContentHash to main thread r=leplatrem
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 78
You need to log in before you can comment on or make changes to this bug.