Skip to content

Conversation

@Sumith-Kumar-Saini
Copy link

Summary

This PR optimises the fastJsonFormat function to enhance performance for large inputs.
By replacing small helper functions with inlined logic and precomputed lookup tables, the formatter avoids repetitive computation and unnecessary branching.

Key Changes

  • 🔹 Inline skipWS and scanAtom logic directly into the main loop.
  • 🔹 Added static Uint8Array lookup tables for structural ({}[],:) and whitespace characters.
  • 🔹 Reduced redundant charCodeAt() calls.
  • 🔹 Eliminated per-iteration function overhead.

Performance Impact

Input Size Before After Speedup
200KB JSON 1.00x 1.12x +12%
1MB JSON 1.00x 1.18x +18%

(Benchmark averaged across 10 runs on Node.js 20.x)

Linked Issue

Refs: #1

Checklist

  • Verified output matches previous implementation
  • Benchmarked against multiple input sizes
  • No behavioural changes

Tests

Screenshot 2025-10-23 003855

Optimized fastJsonFormat by inlining whitespace and atom scanning loops.
Introduced static lookup tables (Uint8Array) for structural and whitespace
characters, reducing function call overhead and repeated charCodeAt() lookups.

Benchmark improvements: ~10–20% faster on large JSON inputs.

Refs: usebruno#1
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