Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,829
    • Issues 4,829
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 444
    • Merge requests 444
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #4167

Closed
Open
Created Jul 03, 2010 by Edward Kmett@ekmett

Add numSparks# to return the number of elements in the current capability's spark queue

Adding

numSparks# :: State# s -> (# State# s, Int# #) 

returning

dequeElements(cap->spark) 

from the c-- backend would permit user code in Haskell to inspect the current capability's spark backlog to decide whether or not to spark a task at all.

Consider how the following combinator from 'speculation' works. Under load, the par will cause the speculation to be discarded, but otherwise it can use it to begin evaluating the function before the argument a is ready, enhancing parallelism if the guess is accurate.

spec :: Eq a => a -> (a -> b) -> a -> b
spec guess f a =
    speculation `par`
        if guess == a
        then speculation
        else f a
    where
        speculation = f guess

Under high load:

foreground: [----- a -----]
foreground:               [-]               (check g == a)
foreground:                 [---- f a ----]
overall:    [-------- spec g f a ---------]

However, a similar combinator needs must degrade much worse under load.

specSTM :: Eq a => a -> (a -> STM b) -> a -> STM b

Due to the fact that the computation of the function is an STM calculation that needs access to the current transaction, it can't be moved into the spark. However, it *could* inspect numSparks# to determine if the current capability's spark queue was loaded and therefore would backlog anyways to avoid evaluating f g at all under load, allowing it to (somewhat clumsily) ape the graceful degradation under load experienced by spec.

This unfortunately cannot be done directly in a third party package using foreign import prim because the capability and spark queue are declared private and so GHC's codebase is the only place that has access to the appropriate primitives.

For more timelines and examples, see 'speculation'.

Trac metadata
Trac field Value
Version 6.12.3
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking