Skip to content

Conversation

@shaungrady
Copy link
Owner

Improved parsing efficiency by replacing character-by-character string
concatenation with native substring slicing operations.

Key optimization:

Substring slicing: Use input.slice(start, end) instead of building
strings char-by-char, eliminating O(n²) behavior for long segment names.

Smart escape handling: Only perform unescaping when escape sequences
are detected via hasEscapes flag (fast path for 99% of segments).

Performance improvements:

  • Overall average: +14% faster
  • Long segments (500 chars): +205% faster (~3x speedup!)
  • Real-world paths: +42-80% faster
  • Bracket notation: +20% faster
  • Deep nesting (26 levels): +8% faster
  • Many segments (50): +49% faster

Minor regression:

  • Escaped characters: -6.7% (still 2.5M ops/sec, rare in practice)

All 488 tests pass. Added comprehensive benchmark suite and detailed
performance analysis. See benchmark/RESULTS.md for full details.

Note: An initial regex-based number validation was tested but
reverted as it slowed down simple single-digit number parsing. V8
optimizes Number() + toString() extremely well for common cases.

claude and others added 4 commits December 2, 2025 23:47
Improved parsing efficiency by replacing character-by-character string
concatenation with native substring slicing operations.

**Key optimization:**

Substring slicing: Use input.slice(start, end) instead of building
strings char-by-char, eliminating O(n²) behavior for long segment names.

Smart escape handling: Only perform unescaping when escape sequences
are detected via hasEscapes flag (fast path for 99% of segments).

**Performance improvements:**
- Overall average: +14% faster
- Long segments (500 chars): +205% faster (~3x speedup!)
- Real-world paths: +42-80% faster
- Bracket notation: +20% faster
- Deep nesting (26 levels): +8% faster
- Many segments (50): +49% faster

**Minor regression:**
- Escaped characters: -6.7% (still 2.5M ops/sec, rare in practice)

All 488 tests pass. Added comprehensive benchmark suite and detailed
performance analysis. See benchmark/RESULTS.md for full details.

**Note:** An initial regex-based number validation was tested but
reverted as it slowed down simple single-digit number parsing. V8
optimizes Number() + toString() extremely well for common cases.
@shaungrady shaungrady merged commit dda8b5f into main Dec 3, 2025
@shaungrady shaungrady deleted the claude/improve-path-parsing-01XdVpG9sy6AKt15jyiZLwaG branch December 3, 2025 00:28
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.

3 participants