StackExchange / StackExchange/StackExchange.Redis
Passing a pooled array to HashSet/StreamAdd and similar methods.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.2k
- Forks
- 1.6k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 43
Description
I have a usecase where allocations need to be minimized and there are scenarios where I get a T[] as an input that needs to be converted to either NameValueEntry[] or HashEntry[] before I can invoke StreamAdd() or HashSet().
One way to tackle this would be to create a buffer using the ArrayPool e.g.
T[] incoming = ...
NameValueEntry[] buffer = ArrayPool<NameValueEntry>.Shared.Rent(incoming.Length)
// copy the items from incoming to buffer
db.StreamAdd(key, buffer);
However given that the buffer.Length returned by the pool is not necessarily same as the requested incoming.Length there is no way for me to indicate how many items StreamAdd()/HashSet() should take.
Would it be possible to create an overload which could support this?
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 by locating the StreamAdd, HashSet, and similar overloads in the StackExchange.Redis client API and review how array lengths are currently handled. Determine the API shape needed to pass the number of valid elements in an ArrayPool-rented buffer, then verify that the overloads use only that range and preserve existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, redis
- Domain
- api, database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100