Created by: natefaubion
I ran some cpu profiles based on the sparkler specs. The three main things that stand out are
syntaxFromToken
resolveCtx
- garbage collection
syntaxFromToken
was using Object.create
but was doing so in such a way that all syntax objects had unique prototypes, rather than sharing. I updated it to use a typical constructor/prototype and saw an immediate 2.5x performance gain.
I would like to look into resolveCtx
but I don't fully understand the flow of it to track down what's going awry. It bounces around a lot. Like, it can go through the renaming cycle several thousands of times. Could you walk me through it, or do you have any insight into why it might be going so crazy?
There are a lot of little things all over the place that produce a lot of garbage that could add up. For example, flatten
uses Array.concat
even though the array is totally localized, so you gain nothing from generating all those copies. On delimiters it even has a chain of three concats, which could be combined into one since its variadic. None of these have a huge effect on their own, but do add up.