microsoft / microsoft/FASTER

Boxing interface usage is allocating unnecessary heap data

Open
#907 3 comments 1 reaction 0 assignees View on GitHub

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 as FasterSession in RmwAsync)

but: any time it is assigned / passed as IFasterSession<...>: it will box, i.e. allocate

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.