Skip to content

Eliminate internal string buffering and write directly to stdout - #142

Open
Bowen951209 wants to merge 8 commits into
PolpOnline:masterfrom
Bowen951209:string-free
Open

Eliminate internal string buffering and write directly to stdout#142
Bowen951209 wants to merge 8 commits into
PolpOnline:masterfrom
Bowen951209:string-free

Conversation

@Bowen951209

Copy link
Copy Markdown
Contributor

This is a minor optimization.

  • Removed State.buffer: Output is now streamed directly to the standard output.
  • Refactored Numeric Formatting: Replaced trim_trailing_zeros() with write_with_precision(). This allows us to format numbers directly into the output stream without needing a back-buffer for post-processing.
  • Updated Tests: Adjusted test cases to align with the new direct-write logic.

- Remove the `buffer` field in `State` struct. Directly write strings
  to stdout.
- Refactor `trim_trailing_zeros()` to `write_with_precision()` because
  we cannot use string buffer. Tests are thus modified.
- Remove sonic-rs dependency. We needed a struct to store text
  and tooltip strings for sonic-rs. Since the string buffer allocations
  are diminished, sonic-rs is no longer useful.
json_escape_simd::escape wraps quotation marks around a string.
Remove them rather than reducing the quotation marks in write_json_unchecked
because of readability.
Validate JSON using sonic_rs, so re-introduced sonic_rs dep.
- Assert the output length is less than 1024 (the stdout line buffer size)
- Assert the output only contains a line break at the last character.
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