Skip to content

feat: offload reconstruction parsing to a background thread via react-native-worklets-core#138

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/consider-offloading-reconstruction-parsing
Draft

feat: offload reconstruction parsing to a background thread via react-native-worklets-core#138
Copilot wants to merge 2 commits intomainfrom
copilot/consider-offloading-reconstruction-parsing

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

Synchronous parseReconstruction runs on the main JS thread after every solve, blocking the UI — most noticeably on gyroscope-equipped smartcubes with dense BLE event streams.

Approach

Introduce react-native-worklets-core to run reconstruction parsing on a dedicated JSI background thread, letting the UI transition immediately while the CPU-intensive solution-analyzer work completes asynchronously.

Changes

  • parseReconstructionAsync.ts (new) — creates a named ReconstructionContext worklet and wraps parseReconstruction in a Promise; errors forwarded via runOnJS(reject)
  • 'worklet' directives — added to parseReconstruction, parseTimestampedMoves, compressDoubleTurns, reconstructionFor, and __reconstructionFor so the Babel plugin serializes the full call chain for background execution
  • PracticeView.tsxhandleSolveComplete refactored to useCallback:
    1. Remove BLE subscriptions and snapshot recordings synchronously
    2. Call setTimerState(TimerState.SCRAMBLING) immediately (zero UI lag)
    3. Parse reconstructions and persist the attempt in the background via Promise.all + .catch
  • babel.config.jsreact-native-worklets-core/plugin added before the Reanimated plugin
  • globalMock.js — Jest mock for react-native-worklets-core (runAsync executes synchronously via Promise.resolve)
// Before: blocks the UI until reconstruction finishes
function handleSolveComplete() {
  const attempt = assembleAttempt(); // ← parseReconstruction runs here, on main thread
  persistAttempt(attempt);
  nextTimerState();                  // ← UI only updates after parsing completes
}

// After: UI transitions instantly; parsing runs in background
const handleSolveComplete = useCallback(() => {
  // ... stop BLE, snapshot recordings ...
  setTimerState(TimerState.SCRAMBLING);          // immediate
  Promise.all(wipSolutions.map(async wip => {
    const reconstruction = await parseReconstructionAsync(...); // background thread
    // ...
  })).then(persistAttempt).catch(console.error); // async, non-blocking
}, [...]);

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • static.realm.io
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/speedcuber-timer/speedcuber-timer/node_modules/realm/node_modules/.bin/prebuild-install --runtime napi (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Consider offloading reconstruction parsing to separate thread feat: offload reconstruction parsing to a background thread via react-native-worklets-core Mar 31, 2026
Copilot AI requested a review from thehale March 31, 2026 17:05
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.

Consider offloading reconstruction parsing to a separate thread via react-native-worklets-core

3 participants