Skip to content

feat: performance improvement (Do not merge maps if the globalForcedVariations or userForcedVariations are empty…#196

Closed
gaurav-rana wants to merge 5 commits intogrowthbook:mainfrom
gaurav-rana:merge_map_optimization
Closed

feat: performance improvement (Do not merge maps if the globalForcedVariations or userForcedVariations are empty…#196
gaurav-rana wants to merge 5 commits intogrowthbook:mainfrom
gaurav-rana:merge_map_optimization

Conversation

@gaurav-rana
Copy link
Copy Markdown
Contributor

@gaurav-rana gaurav-rana commented Mar 12, 2026

… or null)

The stream operations are usually expensive, in our backend app we are observing that 25% of overall GB related overhead is coming from GrowthbookUtils.mergeMaps method. In our case, we dont use feature overrides, so the maps are always empty.
Screenshot 2026-03-11 at 9 08 36 PM

@gaurav-rana gaurav-rana marked this pull request as draft March 12, 2026 04:23
@gaurav-rana gaurav-rana changed the title Do not merge maps if the userFeatures or globalFeatures are empty or … feat: Do not merge maps if the userFeatures or globalFeatures are empty or … Mar 12, 2026
@gaurav-rana gaurav-rana changed the title feat: Do not merge maps if the userFeatures or globalFeatures are empty or … feat: performance improvement (Do not merge maps if the userFeatures or globalFeatures are empty… Mar 12, 2026
@gaurav-rana gaurav-rana changed the title feat: performance improvement (Do not merge maps if the userFeatures or globalFeatures are empty… feat: performance improvement (Do not merge maps if the globalForcedVariations or userForcedVariations are empty… Mar 12, 2026
@vazarkevych
Copy link
Copy Markdown
Collaborator

Hi @gaurav-rana
Thanks for contribution. Is it ready for review?

@gaurav-rana gaurav-rana marked this pull request as ready for review March 24, 2026 17:28
@gaurav-rana
Copy link
Copy Markdown
Contributor Author

Hi @vazarkevych can you please review the PR, its ready for review now!

Copy link
Copy Markdown
Collaborator

@vazarkevych vazarkevych left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, overall looks good! One small suggestion in mergeMaps method. After fix we'll merge it and prepare release

);

public static <K, V> Map<K, V> mergeMaps(@Nullable Map<K, V> base, @Nullable Map<K, V> overrides) {
if (base == null || base.isEmpty()) return overrides != null ? new HashMap<>(overrides) : Collections.emptyMap();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's return new HashMap<>() instead of Collections.emptyMap() for consistency — so the method always returns a mutable map and we prevent a potential UnsupportedOperationException if someone mutates the result in the future.

@madhuchavva
Copy link
Copy Markdown
Contributor

@gaurav-rana Thanks for your contributions. Appreciate it. We have pulled your changes in and added a few improvements. See PR #199. Once it goes through the review process, we'll release it and let you know. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants