-
Notifications
You must be signed in to change notification settings - Fork 128
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
getSelectorFromElement scales poorly with a large DOM and ids with numbers are not used #2751
Comments
Hi @tygary, Thank you for the detailed description. We will look into the performance issue you are facing. In the meantime, let me try to answer your questions:
What need to be rejected is randomly generated ids. This is so the selectors are consistent across all the visitors of your website and can be used to generate heatmaps.
Unfortunately, at this moment this is not possible |
@thomas-lebeau What do you mean by "generated"? As in IDs that are not stable across page loads for the same URL? I would assume you're looking for IDs that are consistent across all users where this ID always means this consistent element for this particular URL? Because in some sense, nearly everything on our page is dynamic and generated. The user can customize and re-arrange items on screen and creating unique IDs that are not numbered is not possible. However, "item-56" may point to one thing at URL A and another totally different thing at URL B. |
At the moment, we either need to disable RUM entirely for customers experiencing slow web pages (which is exactly the opposite of what we'd want from datadog), or we need to get the selector generation under control. Even if that comes at the expense of less usable heatmaps. On a side note, in the datadog browser init I set |
Hey @tygary, thanks again to bring this up to our attention.
It's the idea, yes!
That's also something we want to avoid (ideally, selectors should target something similar across pages). Even if URL A and B are different, they can still share the same "view name". For example, Because this heuristic is not trivial to grasp if you don't have the full context, letting SDK users to customize it (like you are suggesting with providing your own
Selectors are also used for Core Web Vital attribution (identify which element is causing a layout shift for example). This is why you are seeing some selectors even with After some discussion with the team, we have a couple of ideas on how to improve the performance. We still need to implement and test it, but it might solve your issue altogether. In the meantime, you could leverage what we call "stable attributes" here: those attributes are used in the same way as the |
Thanks! For the moment, I have put some ids on a few important elements where I converted the numbers to words. That has fixed the immediate performance issues, but I filed a ticket on myself to remove that hack once we have a better solution or just improved performance. |
Describe the bug
When using the browser agent with RUM enabled, the agent will attempt to resolve a unique selector for every click event.
That process uses
getSelectorFromElement
to perform an iterative algorithm to generate the globally unique selector.However, this process scales in performance along with the size of the dom. In our use-case, for pages with a very large dom the datadog processing on pointerdown will consume 10-25% of the processing time of our entire click event. This is contributing to poor performance on clients with constrained CPU bandwidth.
The ideal solution is to set more ID attributes on our dom to shorten the selectors and improve the queryAll runtime, however the
getIDSelector
method callsisGeneratedValue
with the id and this decides that any id attribute with a number it should not be used as part of the selector.Our UI generally follows this pattern (greatly simplified)
So that excludes all of our ids since everything is numbered or has uuids.
Here is an example selector that gets generated by datadog:
It took ~11ms to generate that selector out of the 45ms of the entire click event and subsequent render, so 25% of the click time was spent on datadog. (This is on my new macbook pro, whereas our customers the click may have taken >250ms and datadog consumes ~75ms and causes significant visual delay)
If we use an attribute like
data-dd-action-name
that brings selector generation down to ~5% of our click time, versus if we use an id selector without numbers ("my-item-fiftysix") that brings the selector generation down to around 1-2% of our click time.In your code inside
isGeneratedValue
is the comment:Why do ids with numbers need to be rejected? Can we provide our own
isGeneratedValue
method to override this?Or must I continue converting numbers into words in our IDs so that the datadog rum agent doesn't cause more latency to our web application. 😞
To Reproduce
Steps to reproduce the behavior:
rum
network request (likefirst_input_target_selector
)Expected behavior
This selector uses the closest id to the clicked element
Actual behavior
The selector generated is extremely long and goes all the way up to the first non-numeric id (basically the root of the dom tree)
The text was updated successfully, but these errors were encountered: