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 Any stack usage #1304

Closed
wants to merge 1 commit into from

Commits on Jul 27, 2023

  1. Improve Any stack usage

    By doing this unsafe approach we are able to save one call to morestack.
    
    Stack usage
    
    SUBQ $0x118, SP       // 280 bytes
    
    Benchmark before
    goos: linux
    goarch: amd64
    pkg: go.uber.org/zap
    cpu: AMD EPYC 7B13
    BenchmarkAny/normal             18570822                61.33 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-2           20671512                59.85 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-4           20064495                58.73 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-8           19763770                60.18 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal_with_logger                  7673887               157.4 ns/op           112 B/op          3 allocs/op
    BenchmarkAny/normal_with_logger-2                8318539               143.0 ns/op           112 B/op          3 allocs/op
    BenchmarkAny/normal_with_logger-4                8584477               139.0 ns/op           112 B/op          3 allocs/op
    BenchmarkAny/normal_with_logger-8                8203886               147.7 ns/op           112 B/op          3 allocs/op
    BenchmarkAny/normal_new_goroutine                 273378              3873 ns/op             137 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-2               496189              2141 ns/op              72 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-4              1000000              1088 ns/op              72 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-8              1743856               678.5 ns/op            72 B/op          2 allocs/op
    PASS
    ok      go.uber.org/zap 15.922s
    
    Benchmark after
    goos: linux
    goarch: amd64
    pkg: go.uber.org/zap
    cpu: AMD EPYC 7B13
    BenchmarkAny/normal             15874744                75.15 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-2           16086948                71.64 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-4           16595194                71.02 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal-8           16130025                72.98 ns/op           24 B/op          1 allocs/op
    BenchmarkAny/normal_with_logger                  9092430               130.0 ns/op            88 B/op          2 allocs/op
    BenchmarkAny/normal_with_logger-2               10157986               122.6 ns/op            88 B/op          2 allocs/op
    BenchmarkAny/normal_with_logger-4                9523335               123.1 ns/op            88 B/op          2 allocs/op
    BenchmarkAny/normal_with_logger-8                9183698               128.2 ns/op            88 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine                1250547               883.7 ns/op            73 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-2              2108619               659.3 ns/op            72 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-4              2919674               407.9 ns/op            72 B/op          2 allocs/op
    BenchmarkAny/normal_new_goroutine-8              4778667               320.5 ns/op            72 B/op          2 allocs/op
    PASS
    ok      go.uber.org/zap 18.898s
    cdvr1993 committed Jul 27, 2023
    Configuration menu
    Copy the full SHA
    ee2a744 View commit details
    Browse the repository at this point in the history