Boxing interface usage is allocating unnecessary heap data
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.6k
- Forks
- 595
- PR merge metrics
- No merged PRs in 30d
Description
scenario: using the async API but fully sync in reality after checking completion; each call issues an InternalFasterSession boxed on the heap;
You can see this by running a memory profiler on this branch (branch: faster-boxing; project: /test/Benchmarks) in DEBUG mode (release mode runs BDN; you don't want that). The test runs 25,000 operations in a loop; the only heap alloc is:
Type Allocations
| - FASTER.core.ClientSession<FASTER.core.SpanByte, FASTER.core.SpanByte, Input, Output, FASTER.core.Empty, CacheFunctions>.InternalFasterSession 25,000
Since InternalFasterSession is a struct, this is unlikely to be intentional.
This is almost certainly where InternalFasterSession is being passed as a IFasterSession<Key, Value, Input, Output, Context> - for example DoSlowOperation, AsyncOperationInternal, etc, which will force it to be boxed. To avoid boxing, the type must be either:
- typed as itself,
InternalFasterSession - "constrained", i.e. passed (and used as) a generic
TSession where TSession : IFasterSession<Key, Value, Input, Output, Context>(used in a few places, such asFasterSessioninRmwAsync)
but: any time it is assigned / passed as IFasterSession<...>: it will box, i.e. allocate
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the test/Benchmarks project on the faster-boxing branch and run the scenario in DEBUG mode under a memory profiler. Trace InternalFasterSession through DoSlowOperation, AsyncOperationInternal, and the constrained FasterSession usage in RmwAsync, looking for interface-typed paths. Done means the 25,000-operation test no longer allocates an InternalFasterSession per call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100