immich icon indicating copy to clipboard operation
immich copied to clipboard

feat(web): wasm justified layout

Open mertalev opened this issue 7 months ago • 3 comments

Description

This is take 2 for #15524 with various improvements since then, including:

  • Safari compatibility
  • Subpixel rendering for better box gaps
  • Improved layout algorithm
  • More ergonomic API

The improvement is very tangible with large buckets and on low/medium grade devices. It also uses less memory.

Notably, unlike earlier attempts to fix Safari issues, the package itself does not require top-level await anymore so there is no strange async code in the asset store or worrying about where to import the module. The initialization is handled in a layout.ts file and the module can be used as normal.

How Has This Been Tested?

Tested on Safari and Chrome on both asset grid and gallery view pages, scrubbing and moving the viewport. On the Flickr30k dataset, I don't observe any incomplete rows and the layout consistently looks good.

mertalev avatar Jun 13 '25 07:06 mertalev

@midzelis I changed the gallery viewer to not make a separate layout array since it wasn't really doing anything that needed a separate array, and it was slower/used more memory than not having it. What's more is that the assignment in the effect was causing the layout to be recalculated whenever you scroll. Making it derived made it so the layout is only generated when the assets change.

I also notice the positions get assigned in the grid to each ViewerAsset. I kept that behavior in this PR, but I wonder if a separate PR to change that would make sense? It would lower RAM usage if you could rely more on the bit-packed layout instead of keeping these position objects around.

mertalev avatar Jun 14 '25 22:06 mertalev

Deploying preview environment to https://pr-19150.preview.internal.immich.cloud/

github-actions[bot] avatar Jun 15 '25 03:06 github-actions[bot]

I think subpixel rendering makes a huge difference. Looks comparable with the original, and feels even faster than before, which is amazing.

midzelis avatar Jun 15 '25 04:06 midzelis