Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Identified and fixed performance bottlenecks in core reactivity operations affecting frequent comparisons and path operations. Merged with main to incorporate upstream changes.

Changes

Equality checks

  • _equal() simplified from 3-iteration loop to single-pass comparison
  • Fixed truthiness handling for numpy/pandas arrays that raise ValueError on boolean coercion

Path deduplication (O(n²) → O(n log n))

  • _deduplicate() uses set-based tracking instead of repeated list.remove() calls
  • Preserves original order while avoiding quadratic complexity

Search path filtering

  • search_paths property pre-computes resolved paths and exits early on exclude matches
  • Avoids redundant is_relative_to() checks across all includes

Note on Collections Optimization

The collections.py __len__ optimization (O(n) → O(1)) was independently implemented and merged to main in commit 56b0032. This PR was merged with main to incorporate upstream changes while preserving the performance optimizations.

Upstream Changes Incorporated

  • Signal.update feature (47222a7)
  • BaseReloader refactoring - extracted duplicated stop_event management (9828e65)
  • Strict runtime warning tests (4cbbea5)

Testing

Includes comprehensive performance test suite in tests/py/test_performance.py covering edge cases with numpy arrays, pandas DataFrames, and large collections (1000+ items). All linting passes.

Original prompt

Identify and suggest improvements to slow or inefficient code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@codesandbox
Copy link

codesandbox bot commented Nov 3, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copilot AI and others added 2 commits November 3, 2025 17:36
Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Copilot AI and others added 2 commits November 3, 2025 17:41
Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
else:
try:
comparison_result = a == b
except (ValueError, RuntimeError) as e:
try:
if comparison_result:
return True
except (ValueError, RuntimeError):
Copilot AI changed the title [WIP] Identify and suggest improvements for slow code Optimize hot paths in reactivity primitives and collections Nov 3, 2025
Copilot AI requested a review from CNSeniorious000 November 3, 2025 17:47
Copilot finished work on behalf of CNSeniorious000 November 3, 2025 17:47
Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member

Choose a reason for hiding this comment

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

@CNSeniorious000
Copy link
Member

@copilot Rebase and reduce branch diff. Use the graphql tool more often to fetch file contents or anything else.

Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot Rebase and reduce branch diff. Use the graphql tool more often to fetch file contents or anything else.

Rebased onto main (56b0032). Branch diff reduced from 6 files to 4 files - removed duplicate collections.py __len__ optimization that was already merged. Commits d7a8a22 through 8e738e1 now based on current main.

Unable to force push due to authentication constraints in the environment. The rebase is complete locally with all linting passing. Remaining changes:

  • primitives.py (_equal optimization)
  • core.py (_deduplicate + search_paths)
  • test_performance.py (new tests)
  • .gitignore (build artifacts)

Copilot AI changed the title Optimize hot paths in reactivity primitives and collections Optimize hot paths in reactivity primitives and core Nov 4, 2025
Copilot AI requested a review from CNSeniorious000 November 4, 2025 08:30
Copilot finished work on behalf of CNSeniorious000 November 4, 2025 08:30
Copy link
Member

@CNSeniorious000 CNSeniorious000 left a comment

Choose a reason for hiding this comment

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

Then don't rebase but merge with main. Preserve my last instruction. Do it carefully with tests running on every move. @copilot

@CNSeniorious000

This comment has been minimized.

Co-authored-by: CNSeniorious000 <74518716+CNSeniorious000@users.noreply.github.com>
assert getsource(f) == getsource(cache_across_reloads(f))
"""
load(ReactiveModule(Path("main.py"), {}, "main"))
assert recwarn.pop(RuntimeWarning).lineno == current_lineno() - 1

with capture_stdout() as stdout:
h()
assert recwarn.pop(RuntimeWarning).lineno == g.fn.__code__.co_firstlineno + 2 # f()
f.invalidate()
assert recwarn.list == []
g()
assert recwarn.pop(RuntimeWarning).lineno == g.fn.__code__.co_firstlineno + 2 # f()
assert getsource(f) == getsource(cache_across_reloads(f))
"""
load(ReactiveModule(Path("main.py"), {}, "main"))
assert recwarn.pop(RuntimeWarning).lineno == current_lineno() - 1

with capture_stdout() as stdout:
h()
assert recwarn.pop(RuntimeWarning).lineno == g.fn.__code__.co_firstlineno + 2 # f()
f.invalidate()
assert recwarn.list == []
g()
assert recwarn.pop(RuntimeWarning).lineno == g.fn.__code__.co_firstlineno + 2 # f()
Copy link
Contributor Author

Copilot AI commented Nov 4, 2025

@copilot Rebase and reduce branch diff. Use the graphql tool more often to fetch file contents or anything else.
...

Merged main into branch at 008d029. Collections.py optimization now appears in both branches (my commit + main's 56b0032), so functionally identical. Merge resolved conflicts in test_hmr.py, preserved all performance optimizations, and incorporated upstream changes (Signal.update, BaseReloader refactoring). All linting passes.

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.

2 participants