-
Notifications
You must be signed in to change notification settings - Fork 11
call computeLibraryElement on all libs, not just entry points #34
Conversation
Oh, another interesting note is that the test actually passes with or without this change, although as I understand it that should not be the case. Any ideas @bwilkerson? Edit: It appears this test is not functioning properly, which presumably means none of these tests are since it follows the same pattern (the validator function is never called). I am looking into this. |
The test looks right to me. Not sure why it wouldn't be broken. |
8ffc879
to
ea50958
Compare
Ok, I fixed the test so it actually runs, and it fails without the change. I am not sure why but the transformer never runs unless there is an export in the file, very bizarre. I will continue to investigate. |
@bwilkerson Ok I just added an option to disable the default behavior (see 2nd commit). I also did a format on the test but pushed that as a separate commit so it wouldn't distract from other changes hopefully. |
I mentioned in mail that it was unclear to me where If I replace Because of this, I don't understand how you can ignore the returned result from |
Hmm, not sure how the tests would be passing then? |
I suspect that the resolved I also suspect that @bwilkerson knows all these things by heart and I hope he'll comment on it. ;-) |
Oh ok I get what you are getting at, I will add a test which I think covers this case (and will likely fail today) |
9423d15
to
a215b3c
Compare
@eernstg ok I added a test and updated the code to use the newly computed library elements. However, I actually noticed that the test passes with the old code as well, which is.... confusing |
a215b3c
to
d7470b6
Compare
@bwilkerson can you take another look and lgtm or provide feedback? |
LGTM (although _performResolve would be cleaner if converted to an 'async' body). |
call computeLibraryElement on all libs, not just entry points
I fetched 'code_transformers' with 'resolve-all-constants' and tried it out with reflectable. It works fine, all tests passing! However, I also completed the branch that I had been working on locally, where reflectable starts with unresolved constants (using 'analyzer' 0.27.2 and an unpatched 'code_transformers' 0.4.0). This version performs constant resolution lazily (and only if it hasn't been done earlier), just before a constant is evaluated, that is, just before First, with the old reflectable using 'analyzer' 0.27.1 we get this result from 10 runs of transforming all 64 test cases in 'test_reflectable', using
Running with 'analyzer' 0.27.2 and the 'code_transformers' on branch 'resolve-all-constants' (that would become the same thing as 'code_transformers' 0.4.1) we get this:
So this is actually about 12% slower than the old 0.27.1 approach. I don't know if this was to be expected, but it seems relevant to know. Finally, here's the result from running the branch of reflectable where I'm using 'analyzer' 0.27.2 and 'code_transformers' 0.4.0 (which would become 0.4.1 where the
So the old 0.27.1 approach as actually 12% slower than this, and the Checking out why there is such a difference, the fine-grained/lazy approach manages to resolve only 53-56 libraries out of 63-74 libraries total. The typical case is 54/63, i.e., one of seven libraries are left unresolved. This makes quite a difference, apparently. So, in the end, I think it makes sense for reflectable to use the fine-grained approach and specify Sorry about giving rise to this change in 'code_transformers' and then not using it. Until some time yesterday I did not think that I had access to any APIs that would allow me to do it inside reflectable. However, I think that it makes a lot of sense to have a 'code_transformers' that resolves all constants by default, and then to allow users to exploit the improved performance associated with a false |
I did also see this slowdown (although it was actually worse, but I was resolving around 400 libraries in my example). I do think it makes sense to have this on by default still though, and having the option to turn it off will allow reflectable to do the more efficient thing. You should also investigate using the new |
I also just published the 0.4.1 version to pub |
Indeed! But we actually use a global |
If you create the |
Referring to the global |
OK, I'll look into that. But which 'phases' are we talking about? How can a transformer know whether barback will call it in one phase or multiple phases? (Presumably that depends on the order of |
Yes, barback will set up Basically though, a single instance of a Transformer would never end up getting used in multiple phases in any real scenarios I know of. |
OK, thanks! |
cc @eernstg @sigmundch
This should resolve the issues that reflectable has been seeing, as well as a few other packages.
An alternative solution to this would be to expose a way of computing individual libraries, but for all current use cases that I know of (reflectable, initialize) this would need to be done for every library anyways :(.
From some really preliminary experiments this significantly increases overall resolve time (highly dependent on app size). However, I don't think it can really be avoided.
See dart-lang/sdk#24890 for more info.