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

Use LZ4 with WASM for volume saving/undo/redo #6652

Merged
merged 21 commits into from
Nov 23, 2022
Merged

Use LZ4 with WASM for volume saving/undo/redo #6652

merged 21 commits into from
Nov 23, 2022

Conversation

philippotto
Copy link
Member

@philippotto philippotto commented Nov 21, 2022

See #5970 and #6652 (comment) for context and numbers.

URL of deployed dev instance (used for testing):

Steps to test:

  • brush and use undo/redo
  • brush and save and reload page
  • everything should work as usual

Issues:


@philippotto philippotto self-assigned this Nov 21, 2022
frontend/javascripts/libs/utils.ts Show resolved Hide resolved
@@ -8,7 +9,7 @@ import anyTest from "ava";
import datasetServerObject from "test/fixtures/dataset_server_object";
import mockRequire from "mock-require";
import sinon from "sinon";
mockRequire.stopAll();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the stopAlls reverted the lz4 mocking (which is necessary since the lz4-wasm module is different for browser and node, unfortunately). it took me a while to figure out that stopAll was the culprit, since it's so inconspicuously in the code. luckily, these statements weren't even necessary.

it's a bit unfortunate that the lz4 mock needs to be at that many places, but I couldn't figure out a better way..

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, extremely impressive improvements! 🤯 Thank you for researching and testing 🙏

Unfortunately, I don't get the mocking yet. Why do files that don't have any direct lz4 usages need to import the lz4 mock? - and wouldn't that also import the mock in production? Why not mock only in the test files where it's needed using mockRequire like we usually do? 🤔

@philippotto
Copy link
Member Author

Why do files that don't have any direct lz4 usages need to import the lz4 mock? - and wouldn't that also import the mock in production? Why not mock only in the test files where it's needed using mockRequire like we usually do?

Oh, two non-spec files slipped in there by accident. I corrected these now.

@philippotto
Copy link
Member Author

Hmm, the wasm doesn't load on the dev instance -.- I'm looking into it..

@philippotto
Copy link
Member Author

Hmm, the wasm doesn't load on the dev instance -.- I'm looking into it..

@fm3 I think the problem is that the backend serves the *.wasm file with content-type: application/octet-stream. However, it needs to be application/wasm. Could you have a look for how to adapt this?

@philippotto
Copy link
Member Author

@daniel-wer please have another look :) now, the deployment at https://lzwasm.webknossos.xyz should work, too.

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with or without my suggestion 👍

During testing of the dev instance, the performance improvement compared to master didn't appear that large. Is that the case for you too? Still, there is an improvement :)

@@ -1,3 +1,4 @@
import "test/mocks/lz4";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of importing the mock in every test file, I think it should work and would be more foolproof to import it once in frontend/javascripts/test/enzyme/e2e-setup.ts or do you think the import order could be problematic, then? 🤔

Sorry to comment on the mocking again. It's no big deal if you leave it as-is.

@philippotto
Copy link
Member Author

During testing of the dev instance, the performance improvement compared to master didn't appear that large. Is that the case for you too? Still, there is an improvement :)

For the record: I measured the performance difference on the dev instance and unfortunately couldn't reproduce the major difference which I observed on localhost before. It seems like the old lz4-js library is way faster (and almost on-par with the wasm library) when being compiled by webpack with production=true.

This observation goes a bit against the benchmark cited here, but I assume it can be explained by: (a) too small inputs or (b) the input is "too easy" to compress which is why the wasm library cannot really show its strengths.

I think, we should proceed with merging this PR nevertheless, since (a) (de)compression will be much faster on localhost (i.e., during development) and (b) the old library doesn't seem to be really maintained, anymore (e.g., the latest commit is from 2018 but the latest release is from 2016).

@philippotto philippotto changed the title Speed up volume saving/undo/redo by using LZ4 with WASM Use LZ4 with WASM for volume saving/undo/redo Nov 23, 2022
@philippotto
Copy link
Member Author

I also bumped the pako library (use for gzip compression when sending save requests) because the version we used dates back to 2015 🙈 The new version is two weeks old. I couldn't see measurable speed improvements, but it shouldn't hurt nonetheless.

@daniel-wer
Copy link
Member

Thank you for re-measuring! I also think we should still proceed with merging this PR 👍

@philippotto philippotto enabled auto-merge (squash) November 23, 2022 13:05
@philippotto philippotto merged commit 7d8ca61 into master Nov 23, 2022
@philippotto philippotto deleted the lz4-wasm branch November 23, 2022 13:23
@fm3 fm3 mentioned this pull request Nov 24, 2022
8 tasks
hotzenklotz added a commit that referenced this pull request Dec 6, 2022
…cing

* 'master' of github.com:scalableminds/webknossos: (23 commits)
  Guard against invalid-mag bucket volume save actions (#6660)
  Add OIDC authentication (#6534)
  Add second (non-admin) default user to "initial data" trigger (#6666)
  Fix and improve miscellaneous things in Folders tab (#6674)
  Improves mag and voxelSize inferral for remote datasets (#6670)
  Squashed commit of the following:
  Fix import of N5 datasets by adding n5 schema to frontend validation (#6668)
  Virtual Folder Structure for Datasets (#6591)
  Ability to recover from webGL context loss (#6663)
  Fix assertion that referenced teams cannot be deleted (#6664)
  fix task summary with pending jobs (#6662)
  Only allow taskTypeId as parameter in task creation (#6640)
  Release 22.12.0 (#6661)
  Create Annotation From View Mode: Keep Activated Mapping (#6647)
  Workaround to avoid false-positive version warning (#6656)
  Fix WK-lib download snippet (#6605)
  Use LZ4 with WASM for volume saving/undo/redo (#6652)
  Fix version number extraction when building docker image (#6655)
  Pass mapping name to precompute meshes (#6651)
  Deduplicate bboxes when importing NML (#6648)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Speed up undo/redo for volume data (with WASM based lz4)
3 participants