-
Notifications
You must be signed in to change notification settings - Fork 544
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
Maps are slow #3113
Maps are slow #3113
Conversation
Benchmarks:
|
3d9e34e
to
7ec20b3
Compare
func (s *span) Attributes() map[traceql.Attribute]traceql.Static { | ||
return s.attributes | ||
func (s *span) AllAttributes() map[traceql.Attribute]traceql.Static { | ||
atts := make(map[traceql.Attribute]traceql.Static, len(s.spanAttrs)+len(s.resourceAttrs)+len(s.traceAttrs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken AllAttributes()
is currently only called once per span. I'm still wondering if it makes sense to cache atts
in the span and skip the copying for consecutive calls to avoid future performance issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to cache it b/c it's possible to have attributes change between calls to AllAttributes()
, but it is a very expensive call and this PR works only b/c we scan so many more spans then we turn them into the results metadata.
I added a comment here to hopefully prevent abuse of AllAttributes()
:
but that's not a great safeguard.
Here are my benchmark results on a 5GB block from ops:
|
480d775
to
a52f87d
Compare
Signed-off-by: Joe Elliott <[email protected]>
Signed-off-by: Joe Elliott <[email protected]>
Signed-off-by: Joe Elliott <[email protected]>
Signed-off-by: Joe Elliott <[email protected]>
Signed-off-by: Joe Elliott <[email protected]>
Signed-off-by: Joe Elliott <[email protected]>
a52f87d
to
e446853
Compare
This PR improves performance of queries that hit the engine layer by reducing allocations and map iterations. It swaps a map of all attributes in the span struct for slices at the span, resource and trace levels.
The AttributeFor function is quite important. It tests the appropriate slices if a scope is provided. Otherwise it checks the slices by attribute name only in order of precedence. This is to replicate this behavior which used to exist in the engine.
Other Changes
AttributeFor()
andAllAttributes()
method. Unfortunately the building of trace metadata requires getting all of the attributes and iterating through them. TheAllAttributes()
method has terrible performance and should generally not be called.AttributeFor()
method. This is more permissive as it first checks for direct matches and then extends its search to check the individual levels by name.Benchmarks below!