|
|
|
|
|
by barrkel
1966 days ago
|
|
If you have large objects which you know you want to deallocate, the easiest way to speed them up is to effectively do manual allocation on top of GC. When you're done with an object (it will almost certainly be an array), push it onto a stack; when you want to allocate, try and pop it off first before allocating fresh. Use stack per thread or locking as appropriate; use multiple stacks with bucketing by size if there's a lot of variance. Use suballocation to reduce reallocating - e.g. allocate 1MB, 2MB, 4MB and so on arrays and keep track of length separately via a slice (array segment). (ArrayPool in .net encapsulates most of this for you these days, but it's a thing I implemented myself back in .net 2 days.) |
|