Skip to content

feat: add high-performance Compact API (#778)#889

Open
blueberrycongee wants to merge 1 commit intobytedance:mainfrom
blueberrycongee:feature/compact-api
Open

feat: add high-performance Compact API (#778)#889
blueberrycongee wants to merge 1 commit intobytedance:mainfrom
blueberrycongee:feature/compact-api

Conversation

@blueberrycongee
Copy link

What type of PR is this?

feat: A new feature

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level.

(Optional) Translate the PR title into Chinese.

feat: 添加高性能 Compact API

(Optional) More detailed description for this PR

en:
Add sonic.Compact() as a high-performance analog of json.Compact. This function removes insignificant whitespace from JSON-encoded data.

Changes:

  • Add public sonic.Compact(dst *[]byte, src []byte) error API
  • Implement fast compaction in internal/encoder/prim with optimized string/escape handling
  • Add compat fallback using encoding/json for non-amd64/arm64 platforms
  • Add comprehensive unit tests and benchmarks

Benchmark results (vs encoding/json.Compact):

Scenario Sonic Std Improvement
Large JSON (~15KB) 406 MB/s 248 MB/s +64%
Small JSON 229 MB/s 160 MB/s +43%

zh:
添加 sonic.Compact() 作为 json.Compact 的高性能替代。大 JSON 性能提升约 64%,小 JSON 提升约 43%。

(Optional) Which issue(s) this PR fixes:

Fixes #778

(optional) The PR that updates user documentation:

N/A (API is straightforward drop-in replacement for json.Compact)

- Add sonic.Compact() as analog of json.Compact
- Implement fast compaction in internal/encoder/prim
- Add compat fallback using encoding/json for non-amd64/arm64
- Add comprehensive unit tests and benchmarks

Benchmark results (vs encoding/json.Compact):
- Large JSON: ~64% faster (406 MB/s vs 248 MB/s)
- Small JSON: ~43% faster (229 MB/s vs 160 MB/s)

Closes bytedance#778
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.

Analog of json.Compact

1 participant