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.
As per #39, the library is fairly slow relative to similar libraries, especially in certain cases (e.g. the example showed in #39 is much slower than
example.toml
from the repo). This PR investigates root causes and works to address performance concerns.Parsing or compiling
A comment in #39 asserts that
compile()
is the likely culprit; I agreed with this assumption, but decided to get some data anyway. I added a new_trace
method that exposes timing data (and allows tracing — more on that later) and updatedbenchmark.js
, and the results surprised me:The most time is spent in peg.js, not in the
compile
function. The next step is to figure out why.I added a tracer that would allow us to count how many times we enter each rule, how many times they match and fail, and the total amount of time spent trying the rules. Enabling tracing of course makes the parser slower; for comparison, here are the overall numbers:
And here's the raw trace data for this run, in CSV form (note times are in nanoseconds):
I imagine analyzing this data will yield some opportunities for performance enhancements.