Skip to content

JavaScript: Improve detection of UMD modules. #8603

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

Merged
merged 4 commits into from
May 31, 2022

Conversation

max-schaefer
Copy link
Contributor

Specifically, we now detect this pattern:

(function (global, factory) {
    checkForNodeJS() ? module.exports = factory(...) :
    checkForAmd() ? define(..., factory) :
    global.mymodule = factory(...)
}(this, function (...) { ... });

We previously missed it because we expected the define to appear as an expression statement, but here it is nested a bit more deeply.

I fixed this by using the inVoidContext predicate we use in a few other queries, which however needed a bit of extra work. I'm curious to see whether that has any knock-on effects on performance or results, if it does I'm happy to switch to a more targeted fix.

@max-schaefer max-schaefer requested a review from a team as a code owner March 30, 2022 09:54
@github-actions github-actions bot added the JS label Mar 30, 2022
@erik-krogh erik-krogh added the no-change-note-required This PR does not need a change note label Mar 30, 2022
@max-schaefer max-schaefer force-pushed the max-schaefer/better-amd-modelling branch from 94c2e0b to 67236e0 Compare March 30, 2022 10:07
erik-krogh
erik-krogh previously approved these changes Mar 30, 2022
Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming an evaluation works out.
(Let me know if you want me to do one for you).

@max-schaefer
Copy link
Contributor Author

Let me know if you want me to do one for you

That would be fantastic, thanks! (The language tests pass.)

@erik-krogh
Copy link
Contributor

Let me know if you want me to do one for you

That would be fantastic, thanks! (The language tests pass.)

I've started one. It should appear as a backref shortly.

@max-schaefer max-schaefer marked this pull request as draft March 31, 2022 08:45
@max-schaefer
Copy link
Contributor Author

The evaluation revealed significant performance regressions that need looking into.

@max-schaefer
Copy link
Contributor Author

I took a quick look at the regression, but didn't make much progress. It's easy to reproduce by, for example, running ClientSideUrlRedirect.ql on openlayers/ol2, which goes from 2s to 105s. We seem to be evaluating a whole load of predicates we previously didn't evaluate (or perhaps they were very quick, I don't know how to read logs anymore these days). I can't justify spending more time on this right now, so I'll just leave this open as a draft in case anyone else wants to pick it up later.

Max Schaefer and others added 4 commits May 30, 2022 12:37
We previously required the `define` to appear directly as an expression statement, but there are common patterns where this is not the case.
@erik-krogh erik-krogh force-pushed the max-schaefer/better-amd-modelling branch from 2c7ec9c to b700972 Compare May 30, 2022 11:56
@erik-krogh
Copy link
Contributor

I've looked a bit at this, and I think I we could merge it now.

New evaluation.

Some of the performance regression seem to have disappeared from just waiting (core improvements?).
But there is still a performance regression left.

However, the cause seems to be that we recognize more flowsteps.
There are several new results, and all the new results (I sampled a few) seem to be from us having a more complete callgraph, which is caused from recognizing more UMD modules.
Some of those new results are eventually FPs (e.g. flow through _.escape(..) in adobe/brackets), but the new edge in the callgraph is good.

I think the trade-off is worth it.

@max-schaefer max-schaefer marked this pull request as ready for review May 30, 2022 13:27
@max-schaefer
Copy link
Contributor Author

I think we could merge it now

Ah, self-fixing performance problems! Those are the best.

@max-schaefer
Copy link
Contributor Author

@erik-krogh, could you re-approve so I can auto-merge?

@codeql-ci codeql-ci merged commit 9dd20f1 into main May 31, 2022
@codeql-ci codeql-ci deleted the max-schaefer/better-amd-modelling branch May 31, 2022 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants