You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Motivation
Adding a new language to Prism takes time. While Prism grammars itself are cheap, our thousands of regexes are not, so loading a large number of grammars can take quite some time.
While Prism evaluates grammars, page loading and rendering are blocked. This means that having Prism choosing a Prism bundle with more languages hurts performance even if those languages end up unused.
Description
Add a way for Prism to lazily evaluate languages. (This should be doable with #2736.)
The performance gain is quite significant. Simply loading a Prism bundle (min) with all languages included takes about 200ms on my machine. Loading that same bundle with lazy evaluation only takes 10ms.
This can be a game-changer, especially on low-end and mobile devices.
Everything is eagerly evaluated:
Only Markup, JS, CSS, and C-like are eagerly evaluated:
(Everything else is wrapped into a function.)
Obviously, Prism Core is always eagerly evaluated.
The text was updated successfully, but these errors were encountered:
I think we'd need to dig into the perf impacts a bit. If we lazily evaluate a grammar that ends up being needed immediately anyway, are we getting any benefits from lazy eval? My suspicion is a loaded language is likely to be used on a given page so the benefits of lazy eval may be limited.
If we lazily evaluate a grammar that ends up being needed immediately anyway, are we getting any benefits from lazy eval?
Probably not. It's mainly useful when you have a large number of grammars and might not need them immediately.
The main use case for this is large bundles. With "large", I mean all languages. Those large bundles are easy to use because they have everything. Users don't have to worry about Autoloader or language dependencies. Everything just works.
Bundle size doesn't matter too much with large bundles (because Prism also works when loaded async) but Prism blocking the page is a problem.
Motivation
Adding a new language to Prism takes time. While Prism grammars itself are cheap, our thousands of regexes are not, so loading a large number of grammars can take quite some time.
While Prism evaluates grammars, page loading and rendering are blocked. This means that having Prism choosing a Prism bundle with more languages hurts performance even if those languages end up unused.
Description
Add a way for Prism to lazily evaluate languages. (This should be doable with #2736.)
The performance gain is quite significant. Simply loading a Prism bundle (min) with all languages included takes about 200ms on my machine. Loading that same bundle with lazy evaluation only takes 10ms.
This can be a game-changer, especially on low-end and mobile devices.
Everything is eagerly evaluated:
Only Markup, JS, CSS, and C-like are eagerly evaluated:
(Everything else is wrapped into a function.)
Obviously, Prism Core is always eagerly evaluated.
The text was updated successfully, but these errors were encountered: