Skip to content

Prepare public API for variable render quantum size #242

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

Merged
merged 4 commits into from
Jan 14, 2023

Conversation

orottier
Copy link
Owner

I think we have settled on most of the public API surface. However in preparation of #217 I think one more modification must be made: remove the constant RENDER_QUANTUM_SIZE.

Relatest to #76 and #140

Might have performance impact. I will add more benchmarks

@github-actions

This comment was marked as outdated.

@orottier orottier force-pushed the feature/prepare-api-for-variable-render-quantum-size branch from 5fa5bc8 to 20e6a6f Compare November 24, 2022 19:57
@github-actions

This comment was marked as outdated.

@@ -75,9 +75,12 @@ impl AllocInner {

/// Render thread channel buffer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AudioRenderQuantumChannel now has no public methods, except the Deref(Mut) to [f32]

@github-actions
Copy link

Benchmark result:


bench_ctor
  Instructions:             5112628 (-0.000039%)
  L1 Accesses:              8164977 (-0.046262%)
  L2 Accesses:                11362 (+0.282436%)
  RAM Accesses:               54499 (-0.011008%)
  Estimated Cycles:        10129252 (-0.037787%)

bench_sine
  Instructions:            78010522 (+0.360178%)
  L1 Accesses:            114253871 (+0.327333%)
  L2 Accesses:               229528 (+0.408145%)
  RAM Accesses:               56807 (+0.003521%)
  Estimated Cycles:       117389756 (+0.322620%)

bench_sine_gain
  Instructions:            83071920 (+0.683357%)
  L1 Accesses:            121828899 (+0.641383%)
  L2 Accesses:               289058 (+0.399433%)
  RAM Accesses:               56128 (No change)
  Estimated Cycles:       125238669 (+0.628461%)

bench_sine_gain_delay
  Instructions:           155109380 (+1.364261%)
  L1 Accesses:            220748819 (+1.117626%)
  L2 Accesses:               670769 (+6.832295%)
  RAM Accesses:               58257 (-0.001717%)
  Estimated Cycles:       226141659 (+1.187688%)

bench_buffer_src
  Instructions:            20289244 (+1.387745%)
  L1 Accesses:             30725543 (+1.218718%)
  L2 Accesses:                63400 (-3.106995%)
  RAM Accesses:               87448 (-0.003430%)
  Estimated Cycles:        34103223 (+1.065919%)

bench_buffer_src_delay
  Instructions:            92831819 (+2.029930%)
  L1 Accesses:            131111642 (+1.681843%)
  L2 Accesses:               159603 (+1.134254%)
  RAM Accesses:               87609 (-0.012554%)
  Estimated Cycles:       134975972 (+1.639461%)

bench_buffer_src_iir
  Instructions:            53623876 (+2.811663%)
  L1 Accesses:             76022968 (+3.056353%)
  L2 Accesses:                73328 (+9.667385%)
  RAM Accesses:               87429 (-0.008006%)
  Estimated Cycles:        79449623 (+2.963465%)

bench_buffer_src_biquad
  Instructions:            41680911 (+1.687413%)
  L1 Accesses:             60287896 (+1.629435%)
  L2 Accesses:               156894 (+14.05413%)
  RAM Accesses:               87502 (-0.009142%)
  Estimated Cycles:        64134936 (+1.685356%)

bench_stereo_positional
  Instructions:            50898776 (+2.300589%)
  L1 Accesses:             77101596 (+2.311961%)
  L2 Accesses:               797108 (+3.744446%)
  RAM Accesses:               87775 (-0.021642%)
  Estimated Cycles:        84159261 (+2.291693%)

bench_stereo_panning_automation
  Instructions:            33766038 (+0.632551%)
  L1 Accesses:             51564946 (+0.037159%)
  L2 Accesses:               131882 (+4.579444%)
  RAM Accesses:               86818 (-0.009214%)
  Estimated Cycles:        55262986 (+0.086478%)


@@ -135,10 +138,10 @@ impl AudioRenderQuantumChannel {
use std::ops::{Deref, DerefMut};

impl Deref for AudioRenderQuantumChannel {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This here is the motivation of the PR. We stop hardcoding the length of the render quantum to 128, but leave it unspecified (we return a slice, instead of an array).
This incurs a small performance hit (a percent, looking at the benchmarks) because more bound checks need to be performed at runtime.
However, this opens the way for the "dynamic render quantum size" feature without breaking the current API. With this PR merged, the RENDER_QUANTUM_SIZE (or, the value 128) is no longer present in the API surface

In preparation of 'variable render quantum size', it is important to
never explicitly expose the buffer size in the public API.

This has a small performance hit though because the new deref signature
forces more bound checks at runtime. It is in the order of a few percent
for some benchmarks.
In the future `RENDER_QUANTUM_SIZE` will not be a constant, but a
property of the BaseAudioContext instead that is based on the
`render_size_hint`
@orottier orottier force-pushed the feature/prepare-api-for-variable-render-quantum-size branch from f7b914c to a5bcf86 Compare January 8, 2023 18:35
@github-actions
Copy link

github-actions bot commented Jan 8, 2023

Benchmark result:


bench_ctor
  Instructions:             5124236 (+0.000312%)
  L1 Accesses:              8195346 (+0.092137%)
  L2 Accesses:                11488 (-0.113034%)
  RAM Accesses:               54565 (-0.010995%)
  Estimated Cycles:        10162561 (+0.071578%)

bench_sine
  Instructions:            80503745 (-0.195567%)
  L1 Accesses:            119198837 (+0.377747%)
  L2 Accesses:               256286 (+10.18030%)
  RAM Accesses:               56671 (-0.010586%)
  Estimated Cycles:       122463752 (+0.464955%)

bench_sine_gain
  Instructions:            85710811 (+0.178673%)
  L1 Accesses:            127045126 (+0.726110%)
  L2 Accesses:               306035 (+4.535859%)
  RAM Accesses:               56120 (-0.010690%)
  Estimated Cycles:       130539501 (+0.757982%)

bench_sine_gain_delay
  Instructions:           157967697 (+1.082371%)
  L1 Accesses:            226344318 (+1.185726%)
  L2 Accesses:               695134 (+5.667232%)
  RAM Accesses:               58202 (-0.010308%)
  Estimated Cycles:       231857058 (+1.239451%)

bench_buffer_src
  Instructions:            20510718 (+1.538293%)
  L1 Accesses:             31272793 (+1.465344%)
  L2 Accesses:                72599 (+4.592932%)
  RAM Accesses:               83932 (-0.001191%)
  Estimated Cycles:        34573408 (+1.370852%)

bench_buffer_src_delay
  Instructions:            93078968 (+2.058787%)
  L1 Accesses:            131491463 (+1.757899%)
  L2 Accesses:               187957 (-1.030988%)
  RAM Accesses:               84112 (+0.005945%)
  Estimated Cycles:       135375168 (+1.699260%)

bench_buffer_src_iir
  Instructions:            53885533 (+2.918596%)
  L1 Accesses:             76477311 (+3.249930%)
  L2 Accesses:                68668 (+3.018483%)
  RAM Accesses:               83883 (No change)
  Estimated Cycles:        79756556 (+3.125561%)

bench_buffer_src_biquad
  Instructions:            41623086 (+1.733026%)
  L1 Accesses:             60199380 (+1.766710%)
  L2 Accesses:               133779 (+5.879699%)
  RAM Accesses:               83978 (+0.001191%)
  Estimated Cycles:        63807505 (+1.725406%)

bench_stereo_positional
  Instructions:            50033892 (+2.256666%)
  L1 Accesses:             75602358 (+2.180579%)
  L2 Accesses:               798560 (+14.19338%)
  RAM Accesses:               84268 (No change)
  Estimated Cycles:        82544538 (+2.622821%)

bench_stereo_panning_automation
  Instructions:            33875099 (+0.825577%)
  L1 Accesses:             51795499 (+0.321908%)
  L2 Accesses:               162512 (+6.584117%)
  RAM Accesses:               83363 (+0.007198%)
  Estimated Cycles:        55525764 (+0.391624%)


@b-ma
Copy link
Collaborator

b-ma commented Jan 9, 2023

Ok I think I see the idea, looks good to me!
(I think I even prefer how we can use the channels this, seems more natural in terms of API)

@orottier orottier marked this pull request as ready for review January 9, 2023 20:15
@orottier orottier merged commit 9a9b265 into main Jan 14, 2023
@orottier orottier deleted the feature/prepare-api-for-variable-render-quantum-size branch June 2, 2023 18:15
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.

2 participants