Optimize AES library to reduce allocations #123039
Replies: 2 comments 5 replies
-
|
Please share a minimal repro. What's the bracktrace for those byte[] s? And what OS? What .NET version? |
Beta Was this translation helpful? Give feedback.
-
|
4216792 / 98212 is 42. I forget what the object overhead is, but feels like it's in the ballpark for a 16 byte buffer to hold the IV state, assuming you're using Windows with an ephemeral key, and thus that "..." is "BasicSymmetricCipherLiteBCrypt". All three of those things (well, all 97203 triplets, the other 1009 arrays presumably came from somewhere else) should be rather transitory and should get cleaned up during gen0 GC. Reducing the allocation any further would require some not-insignificant "plumbing" changes, and potentially no longer sharing code between the stateful and stateless encryption paths. So, it's "possible" to get it down lower, but it isn't (or, at minimum "hasn't been") the top of our areas-for-improvement pile. Is ~128 bytes gen0 per call really being a problem for you, or just a somewhat big-looking number on your profiler? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Is it possible to invoke the native encryptor on Spans? I use the Span-based APIs, but I still get a ton of allocations, and I have a suspicion (without diving in to the code) that it has to do with invoking native stuff. In the screenshot, nearly all of the byte[] allocations are also in encryption. I profiled a hot path which renders a lot of encrypted tokens, and allocations are through the roof, where I was hoping to have near zero. I'm calling
aes.TryEncryptCbc.Beta Was this translation helpful? Give feedback.
All reactions