-
Notifications
You must be signed in to change notification settings - Fork 225
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
Use async_hooks for Node.js 8.2.0 and above #77
Conversation
16572d5
to
75a6d05
Compare
lib/instrumentation/async-hooks.js
Outdated
} | ||
} | ||
function before (asyncId) { | ||
if (!initState.has(asyncId)) return // in case type === TIMERWRAP |
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.
We need to consider if the benefit of filtering out TIMERWRAP
types outweigh the overhead of these has()
calls
6ee9f1c
to
b55231e
Compare
Concern: We'd probably lose context if using AsyncHooks if a call goes through a native module that isn't using n-api. There's work going on to get AsyncHooks to work with Nan in the Node.js Diagnostic WG, but it's far from ready. |
@Qard I just took a look at
|
Ah, right...maybe we can just do some testing around the |
On second thought, this really doesn't matter as it's the same issue with our monkey patched version of the code. |
13fb8c8
to
917b181
Compare
Codecov Report
@@ Coverage Diff @@
## master #77 +/- ##
==========================================
- Coverage 82.51% 80.55% -1.97%
==========================================
Files 38 39 +1
Lines 1922 1939 +17
==========================================
- Hits 1586 1562 -24
- Misses 336 377 +41
Continue to review full report at Codecov.
|
} | ||
|
||
function destroy (asyncId) { | ||
if (!transactions.has(asyncId)) return // in case type === TIMERWRAP |
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 imagine leaving this up to the Map.prototype.delete
function is just as efficient
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.
Same as get
, this may deopt if it tries to delete an item that doesn't exist.
lib/instrumentation/async-hooks.js
Outdated
Object.defineProperty(ins, 'currentTransaction', { | ||
get: function () { | ||
const asyncId = asyncHooks.executionAsyncId() | ||
return transactions.get(asyncId) |
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.
Not sure if it's still the case, but previously map.get(...)
could deopt if the item did not exist. It might be a good idea to put a if (!transactions.has(asyncId)) return
before the get.
} | ||
|
||
function destroy (asyncId) { | ||
if (!transactions.has(asyncId)) return // in case type === TIMERWRAP |
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.
Same as get
, this may deopt if it tries to delete an item that doesn't exist.
Looks like |
@Qard Ah good catch regarding v8.2. I'll update the version requirement 😃 |
@Qard I think this is ready now. If you're ok with it I'll merge it into master and release a new version to npm |
Todo:
TIMERWRAP
- See Use async_hooks for Node.js 8.2.0 and above #77 (comment)promiseResolve
as wellBenchmark the difference in overhead between this solution and the monkey-patching solution in use pre-v8.2.0