Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Share callstack b/w Caller and Stack
A log entry that includes both, the caller and the stack trace requests stack information twice: once to determine the caller and once to build the stack trace. This change optimizes this by requesting call stack information once and sharing it for both cases. --- I ran the benchmarks with `-count 3`. **Before** ``` BenchmarkAddCallerHook-4 1265024 912 ns/op 248 B/op 3 allocs/op BenchmarkAddCallerHook-4 1389937 949 ns/op 248 B/op 3 allocs/op BenchmarkAddCallerHook-4 1327134 862 ns/op 248 B/op 3 allocs/op BenchmarkAddStack-4 565006 1911 ns/op 304 B/op 2 allocs/op BenchmarkAddStack-4 644364 2180 ns/op 304 B/op 2 allocs/op BenchmarkAddStack-4 547028 1896 ns/op 304 B/op 2 allocs/op BenchmarkAddCallerAndStack-4 405864 2471 ns/op 552 B/op 5 allocs/op BenchmarkAddCallerAndStack-4 492368 2940 ns/op 552 B/op 5 allocs/op BenchmarkAddCallerAndStack-4 414658 2588 ns/op 552 B/op 5 allocs/op ``` **After** ``` BenchmarkAddCallerHook-4 1000000 1054 ns/op 240 B/op 2 allocs/op BenchmarkAddCallerHook-4 1245952 1009 ns/op 240 B/op 2 allocs/op BenchmarkAddCallerHook-4 1102441 974 ns/op 240 B/op 2 allocs/op BenchmarkAddStack-4 908425 1269 ns/op 304 B/op 2 allocs/op BenchmarkAddStack-4 774799 1345 ns/op 304 B/op 2 allocs/op BenchmarkAddStack-4 836653 1575 ns/op 304 B/op 2 allocs/op BenchmarkAddCallerAndStack-4 716456 1623 ns/op 544 B/op 4 allocs/op BenchmarkAddCallerAndStack-4 562585 1826 ns/op 544 B/op 4 allocs/op BenchmarkAddCallerAndStack-4 705979 1830 ns/op 544 B/op 4 allocs/op ``` On average, 1. Adding caller alone is ~104 nanoseconds *slower* 2. Adding stack alone is ~600 nanoseconds *faster* 3. Adding both, caller and stack is ~906 nanoseconds *faster* The second of these rightfully raises eyebrows because it was expected to have no changes at best. A cursory investigation doesn't reveal any obvious reason for the speed up unless there's something incredibly wrong with the change.
- Loading branch information