Skip to content

Commit d00e9a9

Browse files
committed
Try to improve performance of denormal flushing
by setting it on the Graph processing level instead of AudioNode
1 parent 0ab338d commit d00e9a9

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/render/graph.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,20 +399,10 @@ impl Graph {
399399
let params = AudioParamValues::from(&*nodes);
400400
scope.node_id.set(*index);
401401
let (success, tail_time) = {
402-
// for x64 and aarch, process with denormal floats disabled (for performance, #194)
403-
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
404-
let process_fn = || no_denormals::no_denormals(|| node.process(params, scope));
405-
#[cfg(not(any(
406-
target_arch = "x86",
407-
target_arch = "x86_64",
408-
target_arch = "aarch64"
409-
)))]
410-
let process_fn = node.process(params, scope);
411-
412402
// We are abusing AssertUnwindSafe here, we cannot guarantee it upholds.
413403
// This may lead to logic bugs later on, but it is the best that we can do.
414404
// The alternative is to crash and reboot the render thread.
415-
let catch_me = AssertUnwindSafe(process_fn);
405+
let catch_me = AssertUnwindSafe(|| node.process(params, scope));
416406

417407
match panic::catch_unwind(catch_me) {
418408
Ok(tail_time) => (true, tail_time),

src/render/thread.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ impl RenderThread {
151151
let num_frames = (length + RENDER_QUANTUM_SIZE - 1) / RENDER_QUANTUM_SIZE;
152152

153153
for _ in 0..num_frames {
154-
// handle addition/removal of nodes/edges
154+
// Handle addition/removal of nodes/edges
155155
self.handle_control_messages();
156156

157-
// update time
157+
// Update time
158158
let current_frame = self
159159
.frames_played
160160
.fetch_add(RENDER_QUANTUM_SIZE as u64, Ordering::SeqCst);
@@ -168,8 +168,14 @@ impl RenderThread {
168168
node_id: Cell::new(AudioNodeId(0)), // placeholder value
169169
};
170170

171-
// render audio graph
172-
let rendered = self.graph.as_mut().unwrap().render(&scope);
171+
// Render audio graph
172+
let graph = self.graph.as_mut().unwrap();
173+
174+
// For x64 and aarch, process with denormal floats disabled (for performance, #194)
175+
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
176+
let rendered = no_denormals::no_denormals(|| graph.render(&scope));
177+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
178+
let rendered = graph.render(&scope);
173179

174180
rendered.channels().iter().enumerate().for_each(
175181
|(channel_number, rendered_channel)| {
@@ -186,10 +192,15 @@ impl RenderThread {
186192
}
187193

188194
pub fn render<S: FromSample<f32> + Clone>(&mut self, output_buffer: &mut [S]) {
189-
// collect timing information
195+
// Collect timing information
190196
let render_start = Instant::now();
191197

192-
// perform actual rendering
198+
// Perform actual rendering
199+
200+
// For x64 and aarch, process with denormal floats disabled (for performance, #194)
201+
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
202+
no_denormals::no_denormals(|| self.render_inner(output_buffer));
203+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")))]
193204
self.render_inner(output_buffer);
194205

195206
// calculate load value and ship to control thread

0 commit comments

Comments
 (0)