HanSolo / medusa

A JavaFX library for Gauges
Apache License 2.0
687 stars 129 forks source link

Performance issue in Gauge getUserAgentStylesheet() #176

Closed chaddaniels closed 4 years ago

chaddaniels commented 4 years ago

I love these gauges, and my application utilizes dozens of them at a time for pending tasks. When using that many instances at a time, I see slowdowns in performance that can be pinpointed to the method getUserAgentStylesheet() from the Gauge class. Rather than looking up the resource every time, would it be possible to look it up the first time as needed, and then cache the resultant String so that future invocations are quick?

As a test, I created a new Gauge sub-class and overrode the getUserAgentStylesheet() method as follows. This seemed to have resolved the performance issue for me.

public class GaugeFix extends Gauge
{
    private static String userAgentStyleSheet;

    public GaugeFix(SkinType skinType)
    {
        super(skinType);
    }

    @Override
    public String getUserAgentStylesheet()
    {
        if (userAgentStyleSheet == null)
        {
            userAgentStyleSheet = Gauge.class.getResource("gauge.css").toExternalForm();;
        }

        return userAgentStyleSheet;
    }
}
HanSolo commented 4 years ago

Fixed with latest commit