-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improve performance of walk utility #4579
Comments
For ref. here is the open Electron issue: I managed to reproduce this once before by inadvertently console logging a huge object which referenced a DOM element. This went through I've also seen Webpack HMR trigger the bug occasionally with whatever it does on update. I suspect it is not enough to only limit the depth we serialise since that can still result in huge objects. We should probably be attempting to limit the number of "leaves" too. |
Here's a related Vue issue: #2957 |
vue 3 some problem. |
Is it still relevant? I can take a look into it, but the |
Hey @AleshaOleg, thanks for your interest! The function is now called sentry-javascript/packages/utils/src/normalize.ts Lines 36 to 43 in 618e992
Not everything in this issue applies anymore, but we haven't profiled it strictly fwiw, I think it's worth it to take a look at a flamegraph and see the bottlenecks. Given we've implemented limiting both breadth and depth and we have a more strict object traversal I'm going to go ahead and close this issue. If you do notice anything after running a benchmark let us know, we can re-open/create a new issue and dive back further into this. |
@AbhiPrasad I wasn't able to figure out how to use the newer benchmark repo. Tried remote setup, but seems it's only for Sentry employees, as I need to access https://run.testa.getsentry.net/. And also not sure why there's only Python platform there. If you have any examples of how to set benchmarks for javascript SDK locally please share them, I would appreciate it. But I tested yesterday with the old benchmark repo - https://github.com/getsentry/sentry-sdk-benchmark/ for the But as there's no more |
Yeah we haven't opened that up for external contributors yet - cool you took a look though! I think we need micro-benchmarks instead of the aggregate benchmarks for latency/CPU that our benchmarking repos give us. I would take a look at https://github.com/davidmarkclements/0x, which is a great tool for generating flamegraphs for small node scripts. |
Got it. Because looked through |
@AbhiPrasad here are some results I got so far. I created a test (based on this one). You can run it from the root in my branch with this command: Below you can see 5 screenshots. For the first 3 it's running As we can see, there's not so much difference if we're changing It really depends on how many times in a row I would say Should I create PR with setup for |
We have a walk util which we use to walk objects to normalize them.
sentry-javascript/packages/utils/src/object.ts
Line 312 in 0a6e535
This is used extensively throughout the SDK, primarily through
sentry-javascript/packages/utils/src/object.ts
Lines 373 to 379 in 0a6e535
@timfish and some others have reported OOM errors on coming from the
walk
function - which shows that it is not always super safe to use. We've also seen issues like #4470.We should try to do a couple things here:
normalize
andwalk
, see where the bottlenecks are in various scenarios. It's used in electron and react native also, so it'll be interesting to see the effects on that platform.JSON.Stringify
replacer to more a more rigorous object traversal to try to improve efficiency.We can test potential performance improvements with https://github.com/getsentry/sentry-sdk-benchmark/
In a slightly related note, we also use
JSON.stringify
a lot throughout the codebase, and it's not always clear when to usewalk
to normalize. We should make the usage consistent, perhaps by extracting into distinct helpers based on the use case. This also means we could have "more expensive" and "less expensive" normalization functions - perhaps that will just alleviate the issue we have here.The text was updated successfully, but these errors were encountered: