-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Move WAITER_NAMES
to global context to reduce warning log spew when this addon becomes v2 and duplicates are allowed
#461
Conversation
|
||
const WAITER_NAME_PATTERN = /^[^:]*:?.*/; | ||
let WAITER_NAMES = DEBUG ? new Set() : undefined; |
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.
the core of this PR is moving WAITER_NAMES
from module-state to state that lives on globalThis
so that it can be shared
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.
It seems like we don't really need this at all. It appears that the purpose of this is just to keep track of what names has been already been used and issue a warning. But in all cases, immediately the waiter is registered on the Map
with that string anyway, so it seems like we could have just checked the map for an existing entry in register
?
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.
yeah it does seem that way -- I was trying to not change how things work too much -- but maybe everything gets way simpler when checking the map. I'll push an update with that, removing WAITER_NAMES
, so the already global WAITERS
is the source of truth.
This would make this PR optional, and it would mean that we can probably proceed with v2-ification without this PR.
The changes coming (not yet pushed) will make the implementation simpler tho, and simpler is still a good thing to have going forward.
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.
nope, this is a false assumption, it seems.
The waiter names are managed like this so you log a warning once per name.
And we def want that to be retained across the globalThis
boundary, so the code stays.
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.
Is this theoretical/hypothetical, or were you actually observing the log spew in tests or something? If it's in tests, I suspect it may be more of an artifact of the test environment than a reflection of reality.
Or maybe I wasn't precise enough when I said do it in register
. I meant the register
in waiter-manager.ts
.
buildWaiter
isn't the kind of thing you intentionally call over and over again. You'd just do it once somewhere in a static (module scope) context. It is possible that it could be called more than once, which is why this warning is here, but it would be due to some accidental module graph duplication or some addon developer programming error (accidentally reusing the same string in multiple files).
But, it seems quite unlikely to me that it will be called repeatedly with the same string so often that we'd have to worry about log spew? I mean, you can force it to happen, by calling it inside a loop, I suppose. But anytime that it is called more than once is already an error situation, and repeatedly over and over again with the same exact string would be some kind of outrageous error situation, and perhaps it isn't even a bad idea to surface it that way if it somehow happens.
So it doesn't seem like a big deal to me to forgo that kind of "protection", and looking at where this was originally introduced (#126), I don't see any reference to the intention of preventing log spews either.
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.
Is this theoretical/hypothetical, or were you actually observing the log spew in tests or something?
This is preparing for switching the library to a v2 addon (See "The Plan"), where we'll have no more highlander code.
Today, with the v1 addon, the WAITER_NAMES stuff is a non-issue because there is only one copy of @ember/test-waiters
-- that will likely not be the case with native v2 addons.
As for hypothetical (due to this library not being v2 yet) -- we're saying that "all waiters, across all parts of the module graph, must have unique names".
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.
That would be an issue even before this PR tho
Yep it is a bug
This is preparing for switching the library to a v2 addon (See #458), where we'll have no more highlander code.
Right but I am specifically talking about the part where you were worried about log spew.
As far as run time behavior and correctness, the global Map already forces the waiters to have unique names or else they would stomp over each other right now. This is true today and also true in the v2 world.
This code we are talking about here only exists to provide a warning about that scenario. What I was proposing is that to tie the warning to the underlying global map and avoid having to track the names separately, which is more code and has the issue I pointed out above where things get out of sync.
In response to that, you mentioned that the way this code is written today would prevent log spews.
I agree that is something that the current code happens to do, but I am not sure it was added specifically for that purpose, or that there are real world scenarios where it would be important to prevent log spews with this API.
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.
but I am not sure it was added specifically for that purpose, or that there are real world scenarios where it would be important to prevent log spews with this API.
So you want log spew in the event there is a naming collision, by means of only checking the Map's keys, and always warn
ing?
What would give you certainty about... anything. I feel like we're not getting anywhere
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.
Ok I was hedging a little bit there and maybe that phrasing confused you. I am saying I didn’t see any evidence that this code is specifically trying to avoid log spew even going back to the original commit. So I am asking where did that concern come from.
Can you read my comment again? I was specifically saying/clarify “it doesn’t seem like we would have to worry about log spew here based on the usage patterns, is there a specific reason you are concerned?”
I was quite specific about why I don’t think that is an issue here and why I didn’t think this was a specific concern when the code was originally added.
I could definitely be wrong but I am asking where did the concern of log spew came from - was it from deductions from analyzing the code, or from discovering the problem when running the tests, etc.
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.
“it doesn’t seem like we would have to worry about log spew here based on the usage patterns, is there a specific reason you are concerned?”
It can happen with a dep graph with duplicate dependencies which would call buildwaiter multiple times.
why I didn’t think this was a specific concern
the highlander code took care of it though, which is why it wasn't a concern.
but I am asking where did the concern of log spew came from - was it from deductions from analyzing the code, or from discovering the problem when running the tests, etc.
the concern comes from
- with native packages, we will have situations where a dep graph contains duplicate dependencies
- with duplicate dependencies, we'll have multiple waiters trying to use the same strings
- if we were to handle the logging in the
register
ofwaiter-manager.ts
, then for each duplicate dependency, we will log extra -- for each duplicate.
I could take the argument that we want to be noisy about this situation and then we should log extra... but I want to be sure that it's a conscious decision.
(In which case, I can move the waiter name checking to use the waiter map's keys, as you've suggested)
a45e358
to
3b7a550
Compare
0e7ea85
to
c16e23c
Compare
cleanup cleanup
c16e23c
to
b7b5968
Compare
WAITER_NAMES
to global context to reduce warning log spew when this addon becomes v2 and duplicates are allowed
Gonna close this PR because the effort is not worth the benefit. The changes we want are going to be in the next major anyway, so if folks want the upcoming benefits, they can upgrade and to an overrides/resolution to get the benefit. The main thing here:
|
Yeah we discussed on Discord –
|
NOTE: this PR will need to target to the
main
branch as well (which I plan on doing after all the test apps are implemented)Context on "The Plan": #458
historically, we've only been able to allow one copy of test-waiters in a whole projcet.
this was forced via build-time code in the v1-addon's index.js.
This added maintenance complexity and prevented the conversion to a v2 addon.
With this runtime injection of global state, we can have both the pre-v2 addon
and the v2 addon share the same waiter state.
Also, in
@ember/test-waiters@v3
, we can force the existing build-time code totake precedecence with the latestVersion of test-waiters v3 (existing behavior),
so there is no risk of old copies of test-waiters not using this runtime highlander code,
because those older copies would not be present in the final build of an app.
So what does this PR actually do?
globalThis
getGlobal
already existed, so much of this work was already doneWAITERS
have already been handledWAITER_NAMES
to also be on the global context, so we don't create a ton of log spew.e.g.:
NOTES