Closed tspiteri closed 4 years ago
r? @brotzeit
(rust_highfive has picked a reviewer for you, use r? to override)
While @phillord is working on optimizing rust-in-macro
in #369 this PR improves rust-ordinary-lt-gt-p
to reduce the number of times rust-in-macro
is called.
Hi @tspiteri,
as for the other PR, some metrics with an example file (like the one you mentionned on the other thread) are very welcome (and would be useful for investigations in the future as well).
The patch looks great (I like the small efficiency gains looking-at => following-char / preceding-char and member => memq). I'd like to take some time to test it and maybe add some test in the suite to capture the behaviour of that code, but I am all for merging.
With the same large file I mentioned in the other PR, the number of calls to rust-in-macro
fell from 935 to 562, which is a fall of about 40%.
Benchmarking using the same code:
(defun bench ()
(goto-char (point-max))
(message "%s"
(benchmark-run 50
(syntax-ppss-flush-cache 1)
(syntax-ppss))))
Before: (224.784685687 3 0.17687254000000002)
After: (114.610272863 3 0.205725889)
I also benchmarked big.rs with/without this patch after applying the latest version of the in-macro-faster patch. While the effect of this patch is reduced, as now rust-in-macro is way faster, this patch still saves an extra 10% in time.
Only in-macro-faster: (9.936009942999998 2 0.09233385400000002)
Both in-macro-faster and this: (8.882999213 2 0.10287831900000002)
Summary bench results:
Without this | With this | |
---|---|---|
Without in-macro-faster | 224.8 | 114.6 |
With in-macro-faster | 9.9 | 8.9 |
Since the check for
->
and=>
is very cheap, move it up inrust-ordinary-lt-gt-p
potentially saving much more expensive checks.Also use simple equality check instead of regex function
looking-at
for checking following character.