Comments (6)
Yeah, I'll profile the code and try to optimize it!
Thanks for pointing at the possible culprit and sorry for introduced regression 🙏 .
I tried to reproduce it and indeed, there's a regression. In my setup (M1 CPU), it was approx. 50% faster than what @klensy posted:
http parser time: [2.0941 ms 2.0948 ms 2.0960 ms]
change: [+500.10% +520.67% +538.10%] (p = 0.00 < 0.05)
Performance has regressed.
json parser time: [124.61 µs 124.65 µs 124.71 µs]
change: [+492.54% +492.97% +493.40%] (p = 0.00 < 0.05)
Performance has regressed.
but it's still a regression / around 5x slower than the previous version baseline.
Without profiling, a few optimization ideas besides reducing the allocations:
- not clearing those tracking structures where possible (and instead keeping track of where last position tokens were added)
- different data structures for lookups: e.g. instead of
call_stack in self.call_stacks.iter().skip(start_index)
to find the deepest rule etc., having a few refs or a HashMap (or BTreeMap) to look it up
But if optimizations can't bring the overhead down to be close to the previous baseline, I guess the best course of action may be to introduce a runtime AtomicBool
flag that one can set if one wants better error reporting? I assume this is better as a runtime option (instead of a compile-time), as one may want to do potentially both: false for default parsing that has a similar performance behaviour as the previous version; true if one wants to explicitly get a better error report?
from pest.
@EmirVildanov do you think that can be optimized? Maybe the allocation can be removed if the token is &str instead of String?
from pest.
Alternatively we can perhaps have this better error reporting as a compile time or runtime option
from pest.
I am also noticed this slowdown. It's very noticeable in real-world situations.
In a private development of branch rustray, I noticed this in the SBT2-parser (for ray tracer scene files).
With pest version 2.7.9:
[*] parse .....: 2139.15 ms
Downgrading to 2.7.8 yields:
[*] parse .....: 297.14 ms
So yeah, about 750% slower :-/
from pest.
I'm guessing the main culprit may be try_add_new_stack_rule
which is called often during parsing and the maintainance of that call stack may be heavy: https://github.com/pest-parser/pest/pull/965/files#diff-4bc69b84e1294b9c791fd94baf98de34748c484129ac9a6c2757babefcf862e0R274
from pest.
@EmirVildanov do you think that can be optimized? Maybe the allocation can be removed if the token is &str instead of String?
Yeah, I'll profile the code and try to optimize it!
Thanks for pointing at the possible culprit and sorry for introduced regression 🙏 .
from pest.
Related Issues (20)
- What does `outer` and `inner` do?
- Pairs has peek() but does not implement Peekable and has a different interface
- hebrew not working properly HOT 1
- Expected operator, found EOI HOT 3
- Predicate failure doesn't cause expression failure HOT 5
- Feature request: Option to use tags to improve error messages
- WHITESPACE and COMMENT require $ to be compound HOT 4
- Async Pest HOT 2
- Very unhelpful error messages for unmapped prefix operators in pratt parsers
- Suggestion: Expose a getter function for LineIndex HOT 3
- Tags on rules that can yield more than one pair
- Wrong tag associated with expression?
- Bug when matching brackets
- `Pairs` can be made with mismatched input `str` and `Vec<QueueableToken>` using `pest::state` HOT 1
- docs(book): documentation is missing for `ASCII` HOT 2
- Using `pest_derive` without `std` under a workspace fails in Windows. HOT 5
- Document panics
- Trigger clippy: empty doc comment HOT 3
- Whitespace ignored between rules HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pest.