WebHost: improve image asset loading performance #4123
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Copyright
All changes made are simple, automated transformations and I do not claim any
copyright over them. The copyright of the original files shall apply to the transformed files.
What is this fixing or adding?
Increase performance when loading the website, both on first visit and repeated visits.
Image resizing
The goal is to improve decoding speed by reducing the total number of pixels.
Renders of landing page at 1x, 2x and 2.4x are attached below.
Most files were resized to meet a device pixel ratio of 3. That is if CSS specifies 100px, the image has 300px.
Device pixel ratio >3 is very uncommon.
Some files were kept as-is because the scaling would have introduced too much blurriness.
Some PC-only (non-mobile) files were resized to meet a device pixel ratio of 2.
Device pixel ratio >2 and zoom level >2 is very uncommon on PC and some of the assets don't meet that anyway.
"Layout shift"
There is a slight shift in the footer at 100% because of a rounding error when scaling, see screenshots below.
Both versions look fine to me.
Cliff atlas
All 8
backgrounds/cliffs/grass/cliff-*
files are put into a singlecliff-atlas
to save 7 requests in the future(once the CSS is changed to use the atlas).
Even with http/2, there is a request queue and more requests means more chances for render to get delayed.
WEBP Recompression
This reduces size, making the transfer faster. Decoding speed is very similar to optimized PNGs.
All but
backgrounds/stone
were compressed losslessly usingcwebp -lossless -q 100 -m 6 "$1" -o "${1%.*}.webp"
backgrounds/stone
was compressed lossy with highest quality usingcwebp -q 100 -m 6 backgrounds/stone.png -o backgrounds/stone.webp
PNG and WEBP look identical to me, PSNR is reported as 54.64 dB.
How was this tested?
See attached screenshots.
Size and loading speed comparison
Time is the time it took to decompress from RAM to RGBA with libpng 1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