juce-framework / JUCE

JUCE is an open-source cross-platform C++ application framework for desktop and mobile applications, including VST, VST3, AU, AUv3, LV2 and AAX audio plug-ins.
https://juce.com
Other
6.54k stars 1.73k forks source link

ValueTree::SharedObject::callListeners optimization #1385

Closed DamRsn closed 3 months ago

DamRsn commented 4 months ago

This PR introduces an optimization to the ValueTree::SharedObject::callListeners method, improving its performance by avoiding a valueTreesWithListeners.contains(v) call when valueTreesWithListeners is not modified by one of the listeners. Instead, valueTreesWithListeners[i] == v is checked before. It gives a significant speedup when numListeners is high.

Note that if i is out of bounds, a nullptr is returned by valueTreesWithListeners[i] and it will compare as not equal to v.

This change improved significantly the performance of preset loading at Minimal Audio (internally using juce::ValueTree::copyPropertiesAndChildrenFrom), so we share it back. See this PR description in our JUCE fork for some indicative benchmarks.

Anthony-Nicholls commented 3 months ago

@DamRsn thanks for sharing, I've pushed a change here https://github.com/juce-framework/JUCE/commit/315167a91a42a520d0a6d3e9fe63f913583329ef