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

perf(image): reduce svgo precision for tracedSVGs #4270

Merged

Conversation

axe312ger
Copy link
Collaborator

While comparing initial html rendering results with different techniques, I found out traced SVG sizes can be reduced by the factor of ~2,2. It even increases the compression rate.

I tried several additional svgo settings but the only one with an higher reduction as 0.01% was to reduce the precision from 1 to 0

Example

My example data is based on gatsbygram which contains 12 traced svg previews.

Method Real Size Gzip Size Compression Ratio Size increase gz
original 36.7 kB (36787B) 10.1kB (10197B) 360,7% 100%
traced svg 313.0kB (313018B) 110.0kB (110078B) 284,3% 1079,5% 😱
traced svg pr 150.8kB (150898B) 49.6kB (49639B) 303,9% 486,80% 💪

Download index.html files of all tests

Compare to other initial rendering image preview techniques

Original - 313.0kB

_users_bene_dev_gatsby_examples_gatsbygram_index-traced-svg-original html ipad pro

Optimized - 150.8kB

_users_bene_dev_gatsby_examples_gatsbygram_index-traced-svg-precision-0 html-no-option html ipad pro

@KyleAMathews
Copy link
Contributor

Looks almost identical! Really nice catch!

@fk look good?

@gatsbybot
Copy link
Collaborator

Deploy preview for gatsbygram ready!

Built with commit a320132

https://deploy-preview-4270--gatsbygram.netlify.com

@fk
Copy link
Contributor

fk commented Feb 27, 2018

Lookin' veeeerrrrrry good!
Thank you @axe312ger! 🙏

/cc @EmilTholin I think you might be interested in that change to floatPrecision too—AFAIR I shamelessly copied the SVGO settings from your loader last year…ah yes: https://github.com/EmilTholin/image-trace-loader/blob/9ee9e5cb6caab17e5ff68a0be5291438b9e5e9dc/lib/index.js#L24

@fk fk self-requested a review February 27, 2018 21:05
Copy link
Contributor

@fk fk left a comment

Choose a reason for hiding this comment

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

👍 🎉

@EmilTholin
Copy link
Contributor

Holy smokes. That's a very nice find! Thank you @axe312ger, and thanks for the ping @fk!

Before: 12657B, 6046B, 15526B, 22795B
before

After: 5502B, 2993B, 6532B, 8171B
after

This might also be a great PR to sqip, which you used in your other PR @axe312ger, if I'm not mistaken?

@axe312ger
Copy link
Collaborator Author

axe312ger commented Feb 27, 2018

Wow cool! Great previews :)

Regarding the sqip svgo tweak:

The effect is way less since it does not use paths and, with a quick test via svgo website, it actually has visible impact on the colors (🤷‍♂️ ) and slightly the positions of shapes. But I could imagine the sqip mode is impacting this a lot.

@axe312ger
Copy link
Collaborator Author

Chrome audit results

This was kind of single run, don't take the numbers to serious. Pages were served locally via https://github.com/zeit/serve which I assume is optimized to imitate a production environment.

I wonder why gatsby-image seems to be unable to render all images at once. Is there any concurrency included?

old gatsbygram with <img src srcSet sizes/> tags

screen shot 2018-02-27 at 23 48 05

new gatsbygram with gatsby-image and tracedSVG

screen shot 2018-02-27 at 23 48 19

@axe312ger
Copy link
Collaborator Author

It actually looks like gatsby-image prevents the images from being loaded in paralell. The fonts and even the js is loaded before the images even start to load.

old gatsbygram with <img src srcSet sizes/> tags

screen shot 2018-02-28 at 00 04 50

new gatsbygram with gatsby-image and tracedSVG

screen shot 2018-02-28 at 00 08 34

@axe312ger
Copy link
Collaborator Author

Performance tab with slow 3g shows similar. While traved svg version offers way better first appearance, it takes twice as much time to load the actual images 😱

screen shot 2018-02-28 at 00 31 08

screen shot 2018-02-28 at 00 31 15

@KyleAMathews
Copy link
Contributor

gatsby-image lazy loads images so images won't load until JS is in which does slow down the initial load of images. We actually should add a prop that lets you disable lazy loading of certain images during SSR (but would lazy load still in the client) for exactly this reason — if an image loading is the critical path for a page, you could simply specify that image as not-lazy.

One thing I worry about with gatsby-image is people sometimes think it's a drop-in replacement for the regular img tag. While it often is, it does make tradeoffs you might not want e.g. here.

@KyleAMathews KyleAMathews merged commit d4f1164 into gatsbyjs:master Feb 28, 2018
@KyleAMathews
Copy link
Contributor

Thanks for finding this and PRing it in!

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.

None yet

5 participants