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

Font Packing Optimisations #400

Open
jacobp100 opened this issue Nov 22, 2019 · 0 comments
Open

Font Packing Optimisations #400

jacobp100 opened this issue Nov 22, 2019 · 0 comments

Comments

@jacobp100
Copy link

jacobp100 commented Nov 22, 2019

So I was optimizing my build of mathjax for an app, and spent some time looking at how fonts are packaged

Currently the metrics data, the SVG path data, and the unicode character are split into three files, and then combined into two fonts at runtime. However, this is really optimizing for the case where the user is exporting to both SVG and chtml in the same page

This splitting adds overhead: you need to duplicate a good amount of the structure of the font when it's split out into this way, you need to include runtime code, and you also need to run the runtime code

We could make two versions of each font, one for SVG and one for chtml

Another optimization we could do is to JSON.stringify these structures at build time and then JSON.parse the strings at runtime - which counter-intuitively speeds up parse time (Chrome Labs Benchmark). We an actually do this regardless of if we combine the font file structures. Webpack does this automatically for any .json file

So in my project, I target only SVG, and I stubbed a most of the font files out with null-loaderMy bundle size before these optimizations was 1.8MB. I did these two optimizations brought this down to 1.5MB - a 300kb reduction. This would have also been a bigger reduction if I had included all the fonts

@jacobp100 jacobp100 changed the title Font Packing Font Packing Optimisations Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants