I've been doing some profiling of CppCheck, and I have an idea for an optimisation but am not sure how feasible it is.
Currently the TemplateSimplifier calculates a Token's scope several tims in several places, in some particularly hot loops. My profiling shows this Match taking 20% of the total runtime or more:
// pattern: {|}|namespace|class|struct|union
I feel like it should be possible to calculate a Token's scope string once and then cache it for the rest of the usages, so the TemplateSimplifier wouldn't need to check if it needs to calculate the current scope. When you add a Token after scopes have been calculated, the new Token's scope would be calculated based on the scope string of the surrounding Tokens.
Does that sound like it would work? I will try and implement it and get a pull request up if people think it is worth trying.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've been doing some profiling of CppCheck, and I have an idea for an optimisation but am not sure how feasible it is.
Currently the TemplateSimplifier calculates a Token's scope several tims in several places, in some particularly hot loops. My profiling shows this Match taking 20% of the total runtime or more:
I feel like it should be possible to calculate a Token's scope string once and then cache it for the rest of the usages, so the TemplateSimplifier wouldn't need to check if it needs to calculate the current scope. When you add a Token after scopes have been calculated, the new Token's scope would be calculated based on the scope string of the surrounding Tokens.
Does that sound like it would work? I will try and implement it and get a pull request up if people think it is worth trying.
I guess it's worth a try. It's interesting that it's so expensive. It must be possible to tweak that somehow.
I've written the code and added a pull request: https://github.com/danmar/cppcheck/pull/1882
It passes the test suite locally and I haven't seen any crashes from running it on other code. In my test code it runs around 30% quicker.