00:01
<Justin Ridgewell>
Because it uses EnqueueMicrotask, which doesn't preserve the context: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/builtins/promise-resolve.tq;l=189;drc=4c61bb3131b7951ed2ed896b4df6110b1e5c072f
01:36
<littledan>
Let me know if I should write this; I am happy to do so but don’t have Edit access
02:13
<Justin Ridgewell>
Send me your email, and I’ll give you edit access
02:14
<Justin Ridgewell>
Or send me notes, and I’ll add them to the deck
02:14
<Justin Ridgewell>
I don’t really know anything about open telemetry
02:18
<Chengzhong Wu>
Sorry I was out yesterday and now I'm back on work. Catching up with the long discussions.
02:29
<littledan>
My email for slides is littledan@chromium.org
02:30
<littledan>
Will post outline of presentation edits here in the coming hours
02:31
<littledan>
So the question then is, is this fixable with V8 changes?
02:35
<littledan>

My notes since legendecas was gone:

  • SES says we are all good!!!!! And the AsyncContext is per agent, not per Realm.
  • V8 has an API that does most of the work for us, and it is cheaper than PromiseHooks. It is called SetContinuationPreservedEmbedderData. However this only handles some things and not others, where we will need plumbing.
  • It actually turns out it makes sense to run the promise unhandled rejections callback in the AsyncContext where the promise was rejected, rather than created. This means we don’t need to instrument the init hook.
02:55
<James M Snell>
I'd add that v8's API will definitely need to be expanded to EnqueueMicrotask in order for thenables to be supported
02:55
<James M Snell>
(And for queueMicrotask)
03:02
<Justin Ridgewell>
Yes, this is due to V8 not fully implementing the host hooks
03:02
<Justin Ridgewell>
All jobs should carry the [[HostDefined]] slot (what they're calling continuation_preserved_embedder_data), but currently only Promise jobs do it
03:46
<littledan>
queueMicrotask is in the same logical bucket as setTimeout though, isn’t it? Like, everything needs plumbing
03:47
<littledan>
But thenables would need built in support otoh
03:48
<Justin Ridgewell>
Kinda, and no
03:48
<littledan>
Note that the job system in the JS spec has historically contained certain… standing disagreements between layers
03:48
<littledan>
The V8 API can do whatever it wants; there is no obligation to match the JS spec
03:49
<littledan>
Anyway this is to say that I don’t know what “all jobs” means
03:49
<Justin Ridgewell>
queueMicrotask seems to be the equivalent of a quick job, and they're not properly implementing the hooks for jobs
03:49
<Justin Ridgewell>
setTimeout might be a job, but I have no idea how it's implemented
03:49
<littledan>
Do you mean literally the function queueMicrotask, or the V8 API used to implement it?
03:49
<Justin Ridgewell>
Sorry, I meant queueMicrotask
03:49
<Justin Ridgewell>
No, EnqueueMicrotask
03:50
<Justin Ridgewell>
Ugh
03:50
<littledan>
Oh! ok, the V8 API
03:50
<littledan>
Now I understand better
03:50
<littledan>
Yeah I can imagine that we need something there
03:51
<Justin Ridgewell>
Specifically, steps 13-15 of https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-promise-resolve-functions are all jobs code, but they're implemented in V8 as a single EnqueueMicrotask
03:52
<Chengzhong Wu>
Node.js tracks queueMicrotask with the async resource API: https://github.com/nodejs/node/blob/main/lib/internal/process/task_queues.js#L152
03:52
<Chengzhong Wu>
similar to setTimeout
03:52
<Justin Ridgewell>
Thenables shouldn't need specific support, the spec for them would work if V8 had fully implemented the job hooks
03:54
<littledan>
Please, let’s make our arguments on the basis of what is useful, not on what someone is expected to do based on how the spec is written. The latter is a weaker argument and less relevant.
03:55
<littledan>
Node.js tracks queueMicrotask with the async resource API: https://github.com/nodejs/node/blob/main/lib/internal/process/task_queues.js#L152
This makes sense to me. Though if the V8 API did something fancier, it might be more efficient.
03:56
<littledan>
This is a place where we should learn from Yoav’s implementation experience
03:57
<Justin Ridgewell>

Please, let’s make our arguments on the basis of what is useful, not on what someone is expected to do based on how the spec is written

Because it prevents an embedder from implementing a feature specifically designed in the spec, I do think it's a problem.

04:03
<littledan>
I think if you make an argument on this basis, you will get a flat no. It just isn’t the contract that engines sign up for.
04:04
<littledan>
If we make an argument based on case by case utility, it will be more effective
04:05
<littledan>
Part of this is, there are some things about the interface Ecma-262 provides which are very wacky and bad; engines don’t actually want to sign up for implementing all of that
04:06
<littledan>
So you are asking for more than you need if you say that they should do everything corresponding to that interface
04:07
<littledan>
Eg it is fine that there is no actual imperative V8 API to get the time zone and that it does things via libc or ICU
04:08
<Justin Ridgewell>
I think we're getting off on a tangent.
04:09
<Justin Ridgewell>
The spec will have explicit requirements for AsyncContext, and when that exists, the hooks won't really matter
04:09
<Justin Ridgewell>
They only matter now because we're trying to shoehorn in AsyncContext
04:09
<Justin Ridgewell>
It's unfortunate it doesn't work properly
04:09
<Justin Ridgewell>
But that'll go away with the real impl
04:09
<littledan>
Yes, the spec will have requirements, and we will also design a V8 API