• Charlie Vieth's avatar
    replacer: evaluate format once and improve perf by ~3x (#3002) · a2af651e
    Charlie Vieth authored
    * replacer: evaluate format once and improve perf by ~3x
    
    This improves the performance of logging by almost 3x and reduces memory
    usage by ~8x.
    
    Benchmark results:
    
    benchmark                                old ns/op     new ns/op     delta
    BenchmarkReplacer-12                     644           324           -49.69%
    BenchmarkReplacer_CommonLogFormat-12     4228          1471          -65.21%
    
    benchmark                                old allocs     new allocs     delta
    BenchmarkReplacer-12                     8              2              -75.00%
    BenchmarkReplacer_CommonLogFormat-12     51             17             -66.67%
    
    benchmark                                old bytes     new bytes     delta
    BenchmarkReplacer-12                     240           48            -80.00%
    BenchmarkReplacer_CommonLogFormat-12     3723          446           -88.02%
    
    * replacer: code review comments
    
    * bufPool: document why we use a pointer to a slice
    * parseFormat: fix confusing comment
    * TestParseFormat_Nodes: rename to TestParseFormatNodes
    
    * replacer: use a value for bufPool instead of a pointer
    
    * replacer: remove comment
    
    * replacer: replace labels with knownLabels
    
    The previous slice of label names is no longer needed.
    a2af651e
replacer.go 6.66 KB