perf(utils): optimize hot-path utilities and fix isObject null bug#12
Merged
Conversation
- hexColor: replace regex/Number() with charCode + parseInt(hex, 16) - isObject: guard against null (typeof null === 'object' bug) - flattenStyles: indexed loop, no per-array closure allocation - gaussian blur: precompute per-row/col edge weight sums (kernel sums to 1 in the interior), drop redundant Uint8ClampedArray copy - spatial nav: compare squared distances (skip Math.sqrt) and replace children.entries() iterator with indexed loop in findClosestFocusableChildIdx Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Skip the intermediate `fns.filter(...)` array; the first two valid functions are tracked in locals, only allocating an array on the 3+ case. - Add a 2-function fast path that unrolls the loop entirely — this is the dominant call shape (props.onX + local handler, props.ref + local ref). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A bundle of small, contained optimizations across the
utilsmodules, plus one correctness fix.hexColor()(src/utils.ts) — swapString.replace+Number()forcharCodeAtchecks +parseInt(hex, 16). Called for every color prop.isObject()(src/core/utils.ts) — bug fix:typeof null === 'object', soisObject(null)returnedtrue, which madehasDebug(null)access.debugonnull. Now guards againstnull.flattenStyles()— replaceforEach(per-array closure alloc) with indexedforloop.weightSumonly deviates near edges. Precompute per-row/per-column inverse weight sums and use1for interior pixels — removes a divide and several adds per pixel.new Uint8ClampedArray(output)copy by writing horizontal pass straight into a dedicated temp buffer.y * widthout of inner loop.distanceBetweenRectCenters→squaredDistanceBetweenRectCenters: dropMath.sqrt(only used for comparison) and the pointless/2on dx/dy.children.entries()iterator with an indexedforloop infindClosestFocusableChildIdx.Test plan
npm run tsccleannpm run lintcleannpm test— 230/230 passing🤖 Generated with Claude Code