Skip to content

Small GenerateOperationId optimization#590

Open
Inok wants to merge 3 commits intoZiggyCreatures:mainfrom
Inok:gen-op-id-perf
Open

Small GenerateOperationId optimization#590
Inok wants to merge 3 commits intoZiggyCreatures:mainfrom
Inok:gen-op-id-perf

Conversation

@Inok
Copy link
Contributor

@Inok Inok commented Feb 1, 2026

Hi!

I noticed that GenerateOperationId is called in almost every operation on the cache. I optimized the implementation a bit:

  • Eliminated boundary checks on the char[] dictionary (replacing to const string helps the compiler to figure out that boundary checks are not needed).
  • Switched from ThreadLocal buffer to stackalloc char[13] on netstandard2.0 (slightly cheaper and has no boundary checks as well).
  • Switched to modern string.Create() on net8.0+ to build the string in place rather than build a buffer and then copy it to the string.

Results:
netstandard2.0 version became slightly faster, but no big difference.
net8.0 version is ~30% faster.

Method Mean Error StdDev Gen0 Gen1 Allocated
GenerateOperationId_Original 15.69 ns 0.221 ns 0.207 ns 0.0038 0.0000 48 B
GenerateOperationId_NetStandard 14.61 ns 0.168 ns 0.158 ns 0.0038 0.0000 48 B
GenerateOperationId_Net8Plus 10.35 ns 0.198 ns 0.186 ns 0.0038 0.0000 48 B

@jodydonetti what do you think?

@Inok
Copy link
Contributor Author

Inok commented Feb 1, 2026

And I also noticed that AOTTester targets net10, but global.json and CI pipeline use .NET 9 SDK, which breaks the build. I bumped SDK to .NET 10 for now, if you don't mind 🙂

@jodydonetti
Copy link
Collaborator

Hi @Inok and thanks for the PR!

Will look at it in the next few days, but it already looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants