StackExchange / StackExchange/StackExchange.Redis

Passing a pooled array to HashSet/StreamAdd and similar methods.

Open
#2,027 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

⚙️ area:API ➕ enhancement 🐌 performance
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.