• Austin Clements's avatar
    runtime: replace traceBuf slice with index · f5c42cf8
    Austin Clements authored
    Currently traceBuf keeps track of where it is in the trace buffer by
    also maintaining a slice that points in to this buffer with an initial
    length of 0 and a cap of the length of the array. All writes to this
    buffer are done by appending to the slice (as long as the bounds
    checks are right, it will never overflow and the append won't allocate
    a new slice).
    
    Each of these appends generates a write barrier. As long as we never
    overflow the buffer, this write barrier won't fire, but this wreaks
    havoc with eliminating write barriers from the tracing code. If we
    were to overflow the buffer, this would both allocate and invoke a
    write barrier, both things that are dicey at best to do in many of the
    contexts tracing happens. It also wastes space in the traceBuf and
    leads to more complex code and more complex generated code.
    
    Replace this slice trick with keeping track of a simple array
    position.
    
    Updates #10600.
    
    Change-Id: I0a63eecec1992e195449f414ed47653f66318d0e
    Reviewed-on: https://go-review.googlesource.com/16814
    Run-TryBot: Austin Clements <austin@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarDmitry Vyukov <dvyukov@google.com>
    f5c42cf8
trace.go 27.2 KB