-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Speedup ChainAnteHandlers by making it non-recursive #14164
Comments
Love the usage of gpt3 here, do you want to submit a pr with the suggested code? Quickly looking at the code it looks like it wont compile. |
Generally I prefer iteration over tail recursion in almost all instances. So I'm in favor of this. |
@alexanderbez want to do some quick bench marks or profiling to see if there is a diff? |
Putting aside the performance issue, I don't see how
which is passed a To illustrate the problem, consider this imlementation:
Now, you could decide that
but that's a subtle restriction, and then why have I suggest replacing
The advantage of |
Yes, exactly. The entire premise of how they run is based on this recursive context. Not sure how much merit there is in keeping this issue open, at least not without strong evidence through benchmarks. |
What's wrong with recursion? Usually it's simpler and more manageable. Compiler should sort it out for an efficient code execution... as long as the recursion is correctly coded. I don't think the performance issues is in recursion. It's rather related to logic or the way how we handle it. |
In one of the profiling I did, for relatively simple transactions, ante handler are heavier than msg execution itself, other than one obvious hotspot of signature verification, the next one is actually |
Params don't use JSON anymore just an FYI. They're proto just like everything else in state. |
ChainAnteDecorators and ChainPostDecorators would create the chaining handler on each invocation repeatedly. This also had the code checking whether the terminator was at the end of the chain. Creating all the handlers upfront and only once improved the performance of `make test-sim-profile` on my local machine from 133.2s to 132s for a ~1% performance improvement. This is similar to cosmos#14164 but maintains the existing recursive behavior.
I think #16076 solves the production speed here, going to close this, and can re-investigate if this appears further in benchmarks's. |
Summary
ChainAnteHandlers surprisingly is a measurable quantity of delay in some of our slow tests in Osmosis. Heres a snippet of it from our IBC tests:
I suggest we make this method non-recursive, to mitigate this. (This is a function created in run-time, so many compiler optimizations don't get applied) I'm in the process of eliminating more of the other overhead. (Raw-time is ~5x'd in our CI)
Here's ChatGPT's code suggestion:
The text was updated successfully, but these errors were encountered: