Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a web worker pool to evaluate interval functions in web workers #264

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

mauriciopoppe
Copy link
Owner

@mauriciopoppe mauriciopoppe commented Dec 17, 2023

Design doc at ./design/web-workers.md

Performance numbers

┌─────────┬───────────────────────────────┬─────────┬───────────────────┬──────────┬─────────┐
│ (index) │           Task Name           │ ops/sec │ Average Time (ns) │  Margin  │ Samples │
├─────────┼───────────────────────────────┼─────────┼───────────────────┼──────────┼─────────┤
│    0    │    'compile and eval 1800'    │  '567'  │ 1761171.361090432 │ '±4.58%' │   284   │
│    1    │ 'async compile and eval 1800' │ '1,430' │ 699015.7267567831 │ '±3.78%' │   716   │
└─────────┴───────────────────────────────┴─────────┴───────────────────┴──────────┴─────────┘

The eval pipeline is now parallelized into groups and sent to the web worker pool.

Results

Sync render

functionPlot({
  target: '#playground',
  width: window.innerWidth,
  height: window.innerHeight,
  data: [
    { fn: 'x^2', nSamples: window.innerWidth*5, sampler: 'interval' },
    { fn: 'sin(x)', nSamples: window.innerWidth*5, sampler: 'interval' },
    { fn: '1/x', nSamples: window.innerWidth*5, sampler: 'interval' },
  ]
})

render sync

Async render

functionPlot.withWebWorkers(8)
functionPlot({
  target: '#playground',
  width: window.innerWidth,
  height: window.innerHeight,
  data: [
    { fn: 'x^2', nSamples: window.innerWidth*5, sampler: 'asyncInterval' },
    { fn: 'sin(x)', nSamples: window.innerWidth*5, sampler: 'asyncInterval' },
    { fn: '1/x', nSamples: window.innerWidth*5, sampler: 'asyncInterval' },
  ]
})

render async

@mauriciopoppe mauriciopoppe merged commit 0a03256 into master Dec 18, 2023
3 checks passed
@mauriciopoppe mauriciopoppe deleted the web-workers branch December 18, 2023 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant