ref(node): parallelize disk io when reading source files for context lines #7374
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed a while back from a customer generated nodejs profile, that the sentry context lines integration was causing a significant slowdown when collecting an error event (iirc in the ballpark of ~200ms). In a long lived process, the cost of this is amortized as we start to hit the file cache more often, however in serverless environments like lambda functions where the cache is short lived, we may still be costing our users some precious execution time.
When I reported this to the SDK team internally and @AbhiPrasad noticed that we actually sequentially read from disk so I wanted to improve this. The changes I made in this PR parallelize i/o read calls and await adding context frames until the source files necessary to do the enrichment have been read.
I ran a quick micro benchmark with a stack trace of 5 frames and assuming the worst case of each file in stack trace being different.
Before/after
-> parallel io x 457,766 ops/sec ±5.07% (83 runs sampled)
-> sequential io x 327,708 ops/sec ±4.96% (81 runs sampled)
Benchmark