-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Optimize opcode price charging #3131
Conversation
Why? negligable performance difference, need a better reason. But i wont block it if you insist. |
On a micro-level there certainly will be a measurable performance difference. |
I want to move it to a inherited jump table, not finished, in this way you can use neo-vm with cost per opcode without neo engine. |
@roman-khimov I know array is more efficient than map, but as you said its micro-level. what is the impact to the general performance? 0.0000000000001%? Should we just swich all foreach to for, cause its also micro-level optimization, but what is the point? remove all LINQ? How about all use Unsafe? We can do this all day just micro level optimization, but contribute nothing to the core performance as they are not the bottleneck. |
Also the |
I don't see how Bloom filter can help here, a flat simple array means accessing this data is a single
For every case like this I'd question myself:
This thing is on the hot path (accessed for every VM instruction), the gain is like in nspcc-dev/neo-go@3c13250 on a micro-level, structurally it's even simpler to me, the only downside probably is type casts that are needed, but this can be mitigated and even now it only affects seven real lines of code. Will it make the node three times faster? Of course not. Do we have any real reason not doing this? I doubt that. |
I will not block this cause it indeed is an "optimization". And yes, it is in the "hot path", but i doubt how much it can improve the performance. you can always go into detail like how many CPU instructions it needs, but this is still not yet the core performance bottleneck, but the StackItem types, SystCalls, Storage IO, reference counters. And I would say you can hardly benchmark the difference. I will try. |
Ok, benchmark with DotnetBenchmark, 2million runs of fetching item from Map and array. BenchmarkDotNet v0.13.12, macOS Sonoma 14.2.1 (23C71) [Darwin 23.2.0]
quite impressive optimization. @shargon great job. |
but instead of removing the original one, please give the Price Array a new name and marke the MapTable as Obsolete, as it is a public interface. |
Done |
Also tested with Assert.AreEqual(ApplicationEngine.OpCodePrices[opcode], ApplicationEngine.OpCodePriceTable[(byte)opcode], $"{opcode} price mismatch"); All same. |
Could you add this test? |
* Allow access TestingEngine to internal (#3134) * Change to public StorageKey constructor * cschuchardt88's feedback * Added `publish` to `github packages` (#3072) * Added nuget packages source * test * Changed to windows * fixed version * fix * fix nuget * fixed nuget.config * Fixed test * Nuget fixes * git * working release * Added cron job * switch to keep 3 packages versions * Update .github/workflows/main.yml * Update .github/workflows/main.yml Co-authored-by: Shargon <[email protected]> * change secret * change delete also --------- Co-authored-by: Jimmy <[email protected]> Co-authored-by: Shargon <[email protected]> * Optimize opcode price charging (#3131) * Optimize price * Jimmy's review * CS0618 * Update tests/Neo.UnitTests/SmartContract/UT_OpCodePrices.cs * Avoid Obsolete --------- Co-authored-by: Jimmy <[email protected]> --------- Co-authored-by: Christopher Schuchardt <[email protected]> Co-authored-by: Jimmy <[email protected]>
Optimize gas charging avoiding dictionary search.