Skip to content

Conversation

@Sumith-Kumar-Saini
Copy link

Description

This PR refactors fastJsonFormat in src/index.js to improve speed, memory efficiency, and Unicode handling.
Key updates:

  • Added decodeUnicodeString() for proper \uXXXX decoding (including surrogate pairs).
  • Used Uint8Array lookup tables for structural and whitespace characters.
  • Switched to chunked string building for better performance on large inputs.
  • Removed legacy helper functions (scanString, scanAtom, etc.) and simplified logic.

Technical Details

  • Fully backward compatible with previous output.
  • Cleaner and more maintainable code with reduced overhead.
  • Improved large-file handling and Unicode correctness.

Benchmark

  • CPU: Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
  • RAM: 16.0 GB
  • GPU: Intel(R) Iris(R) Plus Graphics 655
Screenshot 2025-11-10 004512

Testing

  • Manually verified formatting accuracy and Unicode output.
  • Compared outputs with JSON.stringify and legacy implementation.
  • Passed all existing fastJsonFormat tests.

Sumith-Kumar-Saini and others added 6 commits October 23, 2025 01:12
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
@Sumith-Kumar-Saini
Copy link
Author

@helloanoop, I would be grateful if you could review my pull request.

@helloanoop
Copy link
Contributor

@Sumith-Kumar-Saini can you share screenshots of benchmark run before and after your changes, so that I can see the exact improvement across different data sizes

@Sumith-Kumar-Saini
Copy link
Author

Hey @helloanoop 👋
Please find the benchmark screenshots before and after the changes below.
The left side shows results from the old code (upstream/main), and the right side shows results after my changes.

Benchmarks:

image

System (for reference):

  • Intel Core i5 (4 cores / 8 threads, ~2.4 GHz)
  • 16 GB RAM
  • Integrated Intel GPU
  • Windows 10 Pro

Let me know if you’d like additional sizes or runs.

@helloanoop
Copy link
Contributor

@Sumith-Kumar-Saini This is fantastic. Wanted to have further discussion, Can you accept my connection on Linkedin. Lets talk there

@Sumith-Kumar-Saini
Copy link
Author

Thanks! Glad you found it useful. I've accepted your LinkedIn connection — happy to continue the discussion there.

@helloanoop
Copy link
Contributor

Hey @Sumith-Kumar-Saini Really impressed with the perf improvement 👏 👏

I ran benchmark on my system, while the performance doubles for files around 100kb, it gets worse than the current performance for larger data sizes. Could you check what might be causing that ?

I am running this on Macbook M4 Air 16GB Ram

image

@Sumith-Kumar-Saini
Copy link
Author

Thanks for catching that, @helloanoop, I’ll dig into the large file performance issue and see what’s causing the slowdown — will share an update soon.

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