unleash-client-node icon indicating copy to clipboard operation
unleash-client-node copied to clipboard

Very expensive `convertToMap` function

Open m-sanders opened this issue 1 month ago • 1 comments

Describe the bug

The convertToMap function clones the accumulator on every iteration resulting in O(n2) along with a lot of object instantiations. We have a project with around 1000 flags, resulting in about 500k property assignments, 1000 object instantiations. This is causing noticeable event loop blocks and spikes in GC/s it seems as the flags file is quite large and this is thrashing the garbage collection.

    convertToMap(features) {
        const obj = features.reduce((o, feature) => {
            const a = { ...o };
            this.validateFeature(feature);
            a[feature.name] = feature;
            return a;
        }, {});
        return obj;
    }

The good news is that you've already fixed the code as part of the eslint -> biome migration. Can you release the latest main?

Unleash version

v6.8.0

m-sanders avatar Nov 28 '25 17:11 m-sanders

@m-sanders

We'll make a release shortly. We're just wrapping up some changes currently and then the new version will be released.

FredrikOseberg avatar Dec 02 '25 08:12 FredrikOseberg