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

Optimize zap.Any to use less memory on stack (intermediate props verion) #1308

Closed
wants to merge 1 commit into from

Commits on Aug 1, 2023

  1. Optimize zap.Any to use less mamory on stack (intermediate props vers…

    …ion)
    
    This is an alternative to:
    - #1301 and #1302 and #1304 - a series of PRs that are faster than this
      one. However, they rely on unsafe.
    - #1303 - my own PR that uses closures, to reduce the stack size by 60%.
    - #1305 - my own PR that inline bunch of loops
    - https://github.com/uber-go/zap/compare/pawel/any-int5 that does the
      same as above, but is slightly easier to parse
    - #1307 - a reflect.TypeOf lookup version
    
    THIS PR IS INCOMPLETE - it shows a possible approach, but I wanted to
    get reviewers thoughts before typing everything in.
    
    I originally thought we can use a `type props strucy` intermediary
    struct to store the data, but that hits the same problem: every `props`
    would get it's own slot on the stack. This avoids this by returning
    the raw data.
    
    Pros:
    - the implementation is shared between `Any` and strongly typed Fields
    - no reflect or unsafe
    - reduced the stack significantly - we should be able to get to the same
      ~180 bytes as ~1305.
    - no peft penalty for strongly typed versions, at least on ARM64 it's
      compiled away.
    
    Cons:
    - the code gets a bit harder to maintain. It's significantly better than
      #1305 I would say though.
    rabbbit committed Aug 1, 2023
    Configuration menu
    Copy the full SHA
    09fee60 View commit details
    Browse the repository at this point in the history