Skip to content

Conversation

@jzempel
Copy link
Member

@jzempel jzempel commented Oct 23, 2024

Description

As advertised by the supporting stories, this PR swaps getColor and getColorV8 JSON.stringify argument memoization with a custom key generation backed by WeakMap cached object comparisons. The before/after results are shown below...

Before (JSON.stringify)

Uncached Cached
json-nocache json-cache

After (custom toKey)

Uncached Cached
tokey-nocache tokey-cache

Checklist

  • 👌 design updates will be Garden Designer approved (add the designer as a reviewer)
  • 🌐 demo is up-to-date (npm start)
  • ⬅️ renders as expected with reversed (RTL) direction
  • ⚫ renders as expected in dark mode
  • 🤘 renders as expected with Bedrock CSS (?bedrock)
  • 💂‍♂️ includes new unit tests. Maintain existing coverage (always >= 96%)
  • tested for WCAG 2.1 AA accessibility compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@coveralls
Copy link

coveralls commented Oct 23, 2024

Coverage Status

coverage: 95.89% (-0.001%) from 95.891%
when pulling e6f02ae on jzempel/getcolor-performance
into 5a6c53c on main.

Copy link
Contributor

@ze-flo ze-flo left a comment

Choose a reason for hiding this comment

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

Incredible speed improvement!! 🚄 🚀 🔥🔥

Comment on lines +31 to +32
const BASELINE_NOCACHE = 2780;
const BASELINE_CACHE = 2000;
Copy link
Contributor

Choose a reason for hiding this comment

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

While not critical for this update, we could discuss ways to improve the story without having to rely on a hardcoded BASELINE.

testGetColor();
updateColor(initialColor);

const endTime = performance.now();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is captured after React has completed all state updates. getColor, on its own, is probably much faster than that! 🚀

@jzempel jzempel merged commit d4841cc into main Oct 24, 2024
8 checks passed
@jzempel jzempel deleted the jzempel/getcolor-performance branch October 24, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants