cameron314 / cameron314/concurrentqueue

Pre-allocation of producers

Open
#420 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
12.5k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

As far as I understood, the constructor:

	ConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers)

uses the maxExplicitProducers and maxImplicitProducers to set the initial number of blocks. However, it does not preallocate producers (via add_producer). This means that try_enqueue can still malloc a producer when it is called.

Could the constructor mentioned above also include the following snippet in its body to minimise the chance of malloc when using try_enqueue?

for(size_t i = 0; i != maxImplicitProducers; ++i) {
  auto* p = add_producer(create<ImplicitProducer>(this));
  p->inactive.store(true, std::memory_order_relaxed);
}

Contributor guide

No contributing guide indexed for this repository

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 at the ConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers) constructor and trace add_producer, create, and try_enqueue. Check how producer allocation currently occurs and whether inactive preallocated producers are safe for this queue lifecycle. Done means the constructor preallocates the requested implicit producers and try_enqueue no longer needs to allocate one in the described case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.