Skip to content

Small GenerateOperationId optimization#590

Merged
jodydonetti merged 5 commits intoZiggyCreatures:mainfrom
Inok:gen-op-id-perf
Mar 13, 2026
Merged

Small GenerateOperationId optimization#590
jodydonetti merged 5 commits intoZiggyCreatures:mainfrom
Inok:gen-op-id-perf

Conversation

@Inok
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Hi @Inok and thanks for the PR!

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

@jodydonetti jodydonetti self-assigned this Mar 13, 2026
@jodydonetti jodydonetti added the enhancement New feature or request label Mar 13, 2026
@jodydonetti jodydonetti added this to the v2.6.0 milestone Mar 13, 2026
Copy link
Copy Markdown
Collaborator

@jodydonetti jodydonetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@jodydonetti jodydonetti merged commit b57c6a2 into ZiggyCreatures:main Mar 13, 2026
1 check failed
@Inok Inok deleted the gen-op-id-perf branch March 13, 2026 20:45
@jodydonetti
Copy link
Copy Markdown
Collaborator

Hi all, I just released v2.6.0 🎉

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants