Why is this build lagging on "NumberToStringConverters"?

I posted previously about exceptionally long build and run times for a basic synth test project here:

I tried the suggestions in the thread but did not get any clear solution. Under the presumption that the issue might be the nested FlexBoxes which were a unique component of the design, they were removed and yet I am still having slow build time issues:

https://github.com/jonmdev/SynthPlugin-NoFB

(To be clear, there is still one layer of Flexbox in PluginEditor.cpp, but this can be removed by commenting out the text of the “resized” function and the groups will just stack on each other - doesn’t significantly change the issue either way.)

In this project, build times can randomly vary between 100 ms or so and up to 4 seconds. When it lags on the 4 seconds type builds, this is what it appears to be doing:

Commenting out the group building functions in PluginEditor.cpp gets rid of this build issue, but then of course I have no interface:

createNumPartialsGroup();
createGainGroup();
createEnvelopeGroup();
createDelayGroup();
createdummy1Group();
createdummy2Group();
createdummy3Group();
createdummy4Group();
createdummy5Group();

What does this mean or imply? Where in my code is this coming from and how can it be fixed?

I am at a loss on what to do about this and it is now crippling my progress and designs. Thanks for any help.

Well, if you’re burning all that CPU inside the slider-change callback message, it could be that something is causing them to keep sending unnecessary change messages? Perhaps you’ve got a loop where a slider change triggers something which then changes the slider value and causes another change…

Thanks Jules. That helped to narrow it down.

I’ve isolated the function that is causing the problem, but I’m not sure why it’s causing the problem or how to fix it.

This is in my LabeledComponent.cpp, which is the class that creates sliders, buttons, and comboboxes in my design. The issue is coming from this function to updateLabelText on sliders:

void LabeledComponent::updateLabelText()
{
		String value = String(mSlider->getValue(), mNumberOfDecimalsToDisplay);
		mLabel->setText(value, dontSendNotification);	
}

This function is used in two places in my LabeledComponent.cpp, one of which is problematic (the sliderValueChanged override function).

For more information, here is how the sliders and their labels are constructed:

void LabeledComponent::constructSlider(AudioProcessorValueTreeState& state,
                                       const String& parameterId)
{
    mParameter =
    state.getParameter(parameterId);
    
    mName = mParameter->name;
    
    const float defaultValue = mParameter->getValue();
    mRange = state.getParameterRange(parameterId);
    
    
    Slider* slider = new Slider();
    slider->setName(mName);
    slider->setTextBoxStyle(Slider::TextEntryBoxPosition::NoTextBox, false, 0, 0);
    slider->setSliderStyle(Slider::SliderStyle::RotaryVerticalDrag); 
    slider->setValue(defaultValue, sendNotification);
    slider->setDoubleClickReturnValue(true, defaultValue);
    slider->setRange(mRange.getRange().getStart(), mRange.getRange().getEnd(), 0.001);
    slider->addListener(this);
    mSlider = std::unique_ptr<Slider>(slider);
    addAndMakeVisible(slider);
    

    mLabel = std::unique_ptr<Label>(new Label());
    mLabel->setEditable(true);
    mLabel->addListener(this);
    addAndMakeVisible(mLabel.get());
    
    AudioProcessorValueTreeState::SliderAttachment* attachment =
    new AudioProcessorValueTreeState::SliderAttachment(state, parameterId, *slider);
    mSliderAttachment = std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment>(attachment);
}

The updateLabelText() is called with the override function (which is where the problem occurs):

void LabeledComponent::sliderValueChanged (Slider* slider)
{
   updateLabelText();
}

and this function for setting decimal places:

void LabeledComponent::setNumDecimalPlacesToDisplay(int decimals)
{
    mNumberOfDecimalsToDisplay = decimals;
    updateLabelText();
}

Here is a link to the file LabeledComponent.cpp where this problem is occurring.

If I comment out the updateLabelText() from the sliderValueChanged override then the project loads quickly but the slider labels never change values.

Is there any further clarification that can provided on what needs to be done differently here? Thanks so much.

I’m not sure, but have you try something like:
mlabel.getTextValue().referTo(AudioProcessorValueTreeState(parameterId, nullptr));

Thanks all. I figured it out. It was actually something pretty dumb. The problem was with this function

void LabeledComponent::updateLabelText()
{
		String value = String(mSlider->getValue(), mNumberOfDecimalsToDisplay);
		mLabel->setText(value, dontSendNotification);	
}

The function was designed correctly, but when I debugged mNumberOfDecimalsToDisplay it gave output of:

mNumberOfDecimalsToDisplay-842150451
mNumberOfDecimalsToDisplay3
mNumberOfDecimalsToDisplay-842150451
mNumberOfDecimalsToDisplay2
mNumberOfDecimalsToDisplay-842150451
mNumberOfDecimalsToDisplay3
mNumberOfDecimalsToDisplay-842150451

It turns out it was going into this function uninitialized. And thus Visual Studio was using nonsense like “-842150451” which was trashing the processing because that’s a lot of decimals, and I don’t even know what negative decimals do.

Simple solution. Just initialized it in the header with a simple value:

int mNumberOfDecimalsToDisplay = 1;

Now the project builds perfectly and lightning fast even with the nested flexboxes.

Thanks again guys. I learned a lot from the process if that’s worth anything. And wouldn’t have got there without your pointer @jules