Skip to main content
Tweeted twitter.com/#!/StackProgrammer/status/491331467830915073
deleted 7 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

edit: II suppose I should add that this is an ASP.NET MVC application so everything revolves around requests.

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

edit: I suppose I should add that this is an ASP.NET MVC application so everything revolves around requests.

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

I suppose I should add that this is an ASP.NET MVC application so everything revolves around requests.

added 115 characters in body
Source Link
Casey
  • 273
  • 1
  • 3
  • 10

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

edit: I suppose I should add that this is an ASP.NET MVC application so everything revolves around requests.

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?

edit: I suppose I should add that this is an ASP.NET MVC application so everything revolves around requests.

Source Link
Casey
  • 273
  • 1
  • 3
  • 10

Deferred execution of Dispose for IDisposable objects

I'm working on an application that does lots of encryption and decryption in-application and this is probably the number-one bottleneck, so I've been spending some time making performance tweaks to it. A lot of this has involved simply caching things in memory (I realize there is something of a security tradeoff in doing that), but I noticed during profiling that Dispose() was a fair amount of the time doing decryption (I believe for .NET cryptography stuff it zeroes over everything so this makes sense). So I came up with this idea:

Have a "dispose pool." Instead of using blocks, create objects, use them, return the result, and add them to the dispose pool in the finally block. Internally, the dispose pool uses a queue and a timer and every time the timer fires it dequeues the objects and disposes them.

I tried implementing this and it seems to work and improve performance, but then again, profiling it locally is not a really realistic use case. Is this sound? Am I likely to run into runaway performance issues I'm not currently thinking about?