-
Notifications
You must be signed in to change notification settings - Fork 128
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
scanner: compute token line/column lazily on errors #624
Conversation
Really nice! With faster position computation, we could also use it more frequently to get better logs. This reminds me this article about Megaparsec, a quite fast Haskell parser with really good error messages. One big improvement was computing the exact position (line, column) only on demand. But it also caches it, so the computation does not start from scratch each time. I do not think this is the case here, but it could maybe improve the perf further? |
Nice article, talks exactly about this. I like the caching idea, it should be easy and work well for us, will try it a bit later. |
060f082
to
6d33392
Compare
I added the caching. |
Really nice! Using I would love to see some automated tests based on the stderr output. That would be |
Changing the milestone, I am sure this speedup is very much welcome! |
I am going to write some tests in an independent MR. |
(did not mean to close the PR, sorry for the noise) See #630 for the tests. |
The scanner functions are hot, and the line/column location tracking is quite expensive. We only use it for errors, which don't need to be fast, because we bail if there are too many; and for warnings, which are usually not shown by default. So only keep the token start pos, and compute the line/column lazily from that. This will also allow some further improvements ahead. bench/rulescomp before: compiled 1000 keymaps in 1.669028s after: compiled 1000 keymaps in 1.550411s bench/compose: before: compiled 1000 compose tables in 2.145217s after: compiled 1000 compose tables in 2.016044s Signed-off-by: Ran Benita <ran@unusedvar.com>
Signed-off-by: Ran Benita <ran@unusedvar.com>
6d33392
to
9a00d32
Compare
The scanner functions are hot, and the line/column location tracking is quite expensive. We only use it for errors, which don't need to be fast, because we bail if there are too many; and for warnings, which are usually not shown by default. So only keep the token start pos, and compute the line/column lazily from that. This will also allow some further improvements ahead.
bench/rulescomp
bench/compose: