Skip to content

Optimize getitem#103

Merged
p1c2u merged 1 commit intomasterfrom
feature/optimize-getitem
Feb 18, 2026
Merged

Optimize getitem#103
p1c2u merged 1 commit intomasterfrom
feature/optimize-getitem

Conversation

@p1c2u
Copy link
Copy Markdown
Owner

@p1c2u p1c2u commented Feb 18, 2026

This pull request improves the performance and correctness of the __getitem__ method in AccessorPath by optimizing traversal logic, and adds comprehensive tests and benchmarks to verify and measure these improvements.

Core logic and performance improvements

  • Optimized the AccessorPath.__getitem__ method in pathable/paths.py to minimize redundant traversals and improve efficiency by using direct traversal helpers when available, with compatibility fallbacks for other accessors.

Testing enhancements

  • Added a new CountingTraversableAccessor class in tests/unit/test_paths.py to track the number of traversal operations, enabling precise testing of traversal efficiency.
  • Introduced a test class TestAccessorPathGetItemPerformance to ensure that only a single traversal occurs when accessing a leaf value, validating the performance improvement.

Benchmarking

  • Expanded tests/benchmarks/bench_lookup.py to include benchmarks for __getitem__ operations on both leaf and branch nodes, allowing performance measurement of the new logic.

Type consistency

  • Updated type annotations in MockTraversableAccessor to use Mapping[Any, Any] for improved consistency and generality in tests.

@p1c2u p1c2u force-pushed the feature/optimize-getitem branch 2 times, most recently from 421cfbb to 2267755 Compare February 18, 2026 18:03
@p1c2u p1c2u force-pushed the feature/optimize-getitem branch from 2267755 to 727661d Compare February 18, 2026 18:06
@p1c2u p1c2u merged commit 2a75e00 into master Feb 18, 2026
10 checks passed
@p1c2u p1c2u deleted the feature/optimize-getitem branch February 18, 2026 18:10
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