Hacker News new | ask | show | jobs
by radub 3466 days ago
In the majority of cases, the current layer would have added a log tag to the Context, so looking up the log tags structure will be immediate. On the other hand, we also use OpenTracing and we do have to go through the hierarchy to find the current Span, which will be slower with deep hierarchies.

The other thing to consider is that logging a message carries other costs, so we can't go crazy with very frequent log messages anyway. In our case the message usually also makes its way into an OpenTracing span and that involves memory allocation and/or data copying. My guess is that going through a few linked Contexts is not a big deal, comparatively speaking.

I don't have the kind of benchmark that you are looking for (with vs without using Context), but I can tell you that in the workloads we looked at, tracing was taking a few percentage points (1-2%) of CPU usage, and I don't think a significant part of that was in Context code.

Finally, Context is an interface, so if need be, we can make our own Context implementation that always stores the frequently looked-up things (like log tags, tracing Spans) to short-circuit that cost.