⚡ [performance] Replace slow JSON.stringify with deepEqual in setConfig#2
⚡ [performance] Replace slow JSON.stringify with deepEqual in setConfig#2Elathi wants to merge 1 commit into
Conversation
Replaced JSON.stringify-based deep comparison with a dedicated deepEqual utility in the setConfig hot path. This avoids unnecessary string serialization of the potentially large PaperConfig object, especially the elements array, during frequent updates like dragging. Benchmark results for 1000 iterations with 1000 elements: - Identical objects: ~2x faster - Early difference: ~490x faster Functional correctness verified with test suite. Co-authored-by: Elathi <70385492+Elathi@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Replaced slow
JSON.stringifydeep object equality check in thesetConfigfunction with a more efficientdeepEqualutility.💡 What:
deepEqualfunction inutils.tsthat handles objects, arrays, and primitives.App.tsxto usedeepEqualinstead ofJSON.stringifyin thesetConfigcallback.🎯 Why:
Using
JSON.stringifyfor deep equality is an expensive operation that requires serializing the entire object graph. In the hot path ofsetConfig(which can be called during drag operations), this serialization was a major bottleneck, especially as the number of elements inPaperConfiggrew.📊 Measured Improvement:
Using a benchmark script with a configuration containing 1000 elements:
deepEqualis ~2x faster thanJSON.stringify.deepEqualis ~490x faster because it short-circuits immediately when a difference is found, whereasJSON.stringifymust always serialize the entire object.This change ensures that state updates remain smooth and efficient, particularly during user interactions.
PR created automatically by Jules for task 17939495821773399236 started by @Elathi