Open mtths opened 1 month ago
We are affected by this as well. According to NYTProf, most of the time is spent here: https://github.com/Perl-Critic/PPI/blob/d9554383fc9f28adccc5dfd4284da53174cb14d7/lib/PPI/Token/Whitespace.pm#L215 (and then I got lost in recursion)
We are affected by this as well. According to NYTProf, most of the time is spent here:
PPI/lib/PPI/Token/Whitespace.pm
Line 215 in d955438 my ( $has_sig, @tokens ) = $t->_current_token_has_signatures_active; (and then I got lost in recursion)
I've tried doing a NYTProf flame chart on a file for 700 seconds, and it looks like the big problem is PPI::Element::presumed_features
.
Whenever it is called; it does a full traversal back up every previous sibling, and every previous sibling of every parent, from the point of spotting a potential function signature.
The traversal in itself takes ~90s of the 700s; and 500s is then spent of calling feature_mods
.
It seems like a lot of repeated work is being done here.
The function call shown by @jixam is as far as I can tell being called every time the tokenizer encounters a (
- traversing through the entire syntax tree each time. No wonder it's super slow.
I would imagine this could be sped up immensely by caching the results. Perhaps each node in the syntax tree could keep track of the current feature status of that statement; so it wouldn't have to traverse through the entire tree, but just ask the previous node, and update that based on the current statement.
If someone would like to provide a pull request to fix this, I can look at getting it released.
Fwiw, i have talked with @mtths about this and currently this is lower on my priority list than other todos with PPI.
That said: Yes, caching is probably the solution. However in that case we also need to consider how to invalidate the cache when the structure gets edited. Possibly the cache could be temporary while a fragment is being parsed.
This makes PPI pretty much unusable for a lot of cases. At my work we've downgraded to the previous version.
I'm baffled as to what you could be doing that would render it unusable, but alright. I'll try and see if i can get a solution of caching and end-of-parse invalidation done tomorrow. If anybody else wants to give it a shot and maybe be faster than me, be my guest. :)
we saw quite a slowdown in parsing times with the latest PPI, especially in our fatter modules (up to a factor of 20)
the slowdown seems to occur in parsing the document during object creation. method calls on the parsed document have similar call times as before
we use PPI for checking syntax and via perlcritic