-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse contract instance for better performance (#2628)
# Description First task of #2627 Creating contract instances with `ethcontract-rs` is very costly (especially in tight loops). A very significant amount of time is spent creating instances to query allowances. # Changes Instead of creating 1 contract instance per token to fetch balances for we now create a single erc20 instance and reuse it for all `allowance()` calls. This is unfortunately pretty ugly since `ethcontract-rs` doesn't really expose the generated calldata very nicely and doesn't really compose with `web3`. ## How to test Correctness should be covered by e2e tests Performance was verified using the benchmark mentioned in #2627 It's a bit hard to see but fetching allowances went from ~20% to ~7.6% of the entire runtime. The overall runtime of the axum request handler went from ~74% -> 63% of the runtime. Overall I think the performance gains are significant enough to warrant the slightly ugly but very local performance hack until we replace `ethcontract-rs` with `alloy` entirely. Before <img width="1728" alt="Screenshot 2024-04-17 at 21 32 46" src="https://github.com/cowprotocol/services/assets/19190235/9d8d9cdf-ed72-4bff-a40b-c3cbf5418dbf"> Optimized <img width="1728" alt="Screenshot 2024-04-17 at 21 28 35" src="https://github.com/cowprotocol/services/assets/19190235/005aa2cd-7679-4d49-8220-c86cd25988a1">
- Loading branch information
1 parent
ae05328
commit 03c69f9
Showing
1 changed file
with
52 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters