typelevel / typelevel/cats-effect

Add parallelismFactorHint to Spawn[F]

Open
#4,199 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
2.2k
Forks
576
Avg merge
2d 11h
Merged PRs (30d)
18

Description

Someone asked in Discord if there is a way to ask the CE runtime how many CPUs/compute threads it has access to, so that they can set parallelism factors appropriately. It's available in IOApp as computeWorkerThreadCount but this is specific to IOApp and therefore not easily usable from all the places in c.e.std that could benefit from it.

Once it's added to Spawn, new methods or overrides should be added setting default parallelism factors accordingly. For example, in addition to Random.scalaUtilRandomN, there should be a variant that sets N to the computeWorkerThreadCount.

There was some discussion of this in Discord, which I will attempt to summarize:

  1. Daniel originally suggested it as concurrencyFactorHint: Option[Int] (or parallelismFactorHint: Option[Int] in the interest of consistent terminology).
  2. Arman suggested avoiding the Option box by defaulting to 0, to which Daniel "didn't totally object," because "technically anything ≤ 0 is semantically invalid anyway" and "if we go with 0 as the default then the fallback could be to tap the runtime anyway"
  3. There was also some discussion about whether this should be F[Int] to reflect the reality that the number can change in some circumstances, but that opens up quite a rabbit hole, so it may not be worth it? If F[Int] is used, should there be some kind of notification protocol to let data structures optimized for a given value rebalance themselves if the value changes?

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 reading computeWorkerThreadCount in core/jvm/src/main/scala/cats/effect/IOApp.scala and the Spawn API. Then inspect Random.scalaUtilRandomN and other c.e.std defaults mentioned in the issue. Done means the design is resolved, Spawn[F] exposes the hint, and appropriate default-factor variants are added and tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
backend, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.