Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve string encoding by following json approach #1350

Merged
merged 9 commits into from
Sep 9, 2023

Commits on Sep 8, 2023

  1. Improve string encoding by following json approach

    Benchmark results
    
    goos: linux
    goarch: amd64
    pkg: go.uber.org/zap/zapcore
    cpu: AMD EPYC 7B13
                   │ /tmp/old.txt │            /tmp/new.txt             │
                   │    sec/op    │   sec/op     vs base                │
    ZapJSON-8         89.10µ ± 1%   33.38µ ± 3%  -62.54% (p=0.000 n=10)
    StandardJSON-8    40.74µ ± 1%   42.46µ ± 1%   +4.22% (p=0.000 n=10)
    geomean           60.25µ        37.65µ       -37.52%
    cdvr1993 committed Sep 8, 2023
    Configuration menu
    Copy the full SHA
    414a7b5 View commit details
    Browse the repository at this point in the history

Commits on Sep 9, 2023

  1. Configuration menu
    Copy the full SHA
    044300b View commit details
    Browse the repository at this point in the history
  2. Buffer.AppendBytes: Fix doc

    abhinav committed Sep 9, 2023
    Configuration menu
    Copy the full SHA
    e12743b View commit details
    Browse the repository at this point in the history
  3. chore: Inline tryAddRuneError

    This no longer needs to be a separate function.
    abhinav committed Sep 9, 2023
    Configuration menu
    Copy the full SHA
    85815f6 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    9165693 View commit details
    Browse the repository at this point in the history
  5. test: Add fuzz test for safeAppendStringLike

    Adds a fuzz test for the string and []byte versions of safeAppendStringLike
    that verifies that both variants are able to decode the original string
    back.
    abhinav committed Sep 9, 2023
    Configuration menu
    Copy the full SHA
    f974d60 View commit details
    Browse the repository at this point in the history
  6. perf: Apply the same optimization to multi-byte runes

    The optimization is basically "instead of appending byte at a time,
    skip over non-special bytes and append them all together."
    The original optimization applies only to single-byte runes.
    This applies the same to multi-byte runes.
    abhinav committed Sep 9, 2023
    Configuration menu
    Copy the full SHA
    c00d33c View commit details
    Browse the repository at this point in the history
  7. chore: More readable

    Flips the logic a little to be easier to follow.
    The shape is basically:
    
        if mutli byte rune {
            if no special handling {
                skip
                continue
            }
            special handling
        } else {
            if no special handling {
                skip
                continue
            }
            special handling
        }
    
    This makes the logic much more obvious while retaining performance.
    abhinav committed Sep 9, 2023
    Configuration menu
    Copy the full SHA
    dc239f1 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    ced79e2 View commit details
    Browse the repository at this point in the history