Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing colorKit: Running on the UI Thread for Enhanced Performance #52

Merged
merged 3 commits into from
Jan 6, 2024

Conversation

alabsi91
Copy link
Owner

@alabsi91 alabsi91 commented Jan 6, 2024

I refactored colorKit to make it run on the UI thread. To achieve this, I combined all colorKit methods into a single function. The reason I didn't add the 'worklet' directive to each method is that the react-native-reanimated Babel plugin will transform it into something like this:

Before:

function clamp(v: number, max: number) {
  'worklet';
  return Math.min(Math.max(v, 0), max);
}

After Transformation:

const _worklet_1297586879362_init_data = { ... };

const clamp = (function () {
  const _e = [new global.Error(), 1, -27];
  const anonymous = function (v, max) {
    return Math.min(Math.max(v, 0), max);
  };
  anonymous.__closure = {};
  anonymous.__initData = _worklet_1297586879362_init_data;
  anonymous.__workletHash = 1297586879362;
  anonymous.__stackDetails = _e;
  return anonymous;
})();

Although the initial load time might be significantly affected, the trade-off is understandable given the substantial benefit of being able to run any colorKit methods on the UI thread.

@alabsi91 alabsi91 merged commit d96eee9 into main Jan 6, 2024
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.

1 participant