-
Notifications
You must be signed in to change notification settings - Fork 1.8k
JS: Cache some SourceNode getter methods differently #3335
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
JS: Cache some SourceNode getter methods differently #3335
Conversation
Very nice!! But it is also very sad that this is required. I think we should merge, but lets discuss some consequences of this PR first: So now call.getReceiver().flowsFrom(x) // (new predicate, as an alternative to `flowsTo`)
call.getReceived.getALocalSource() = x Should we adopt a code style flow that follows the evaluator flow for local data flow? That is: call.getReceived.getALocalSource() = x
x.getAMethodCall() = call is preferred to: x = call.getReceived.getALocalSource()
call = x.getAMethodCall() Since the left-to-right reading order matches the evaluator flow. I am not advocating rewriting our existing code to match this pattern, but we could adopt it moving forward, or perhaps add a comment when it truly matters. |
I think it's too soon to say if it should be deprecated, but I'll go over our existing uses of
I personally like it very much when the code has an obvious evaluation order, and would try to order conjuncts accordingly. Your suggested style sounds reasonable when chaining local data flow together (though I don't think |
Do you want to do that before or after the merge of this PR? |
After. But first I have to fix these test failures that are making me nervous 😬 |
Fair enough. |
The test failure was due to An evaluation of XSS/smoke-test shows performance is still positive, so I'm willing to believe that this didn't impact performance, but I can run another evaluation if anyone thinks it's needed. For now, I'll wait for the original big-apps evaluation to finish. |
XSS/big-apps looks good as well |
We now cache the heavily-used getters in
SourceNode
(or rather, some helper predicates they are based on). Previously they relied on the optimizer getting creative with magic.Apart from a speed-up here and now, I'm hoping this will lead to more stability when we make changes to the standard libraries, as an unrelated change won't affect how these central predicates are optimized.
One thing to note is that
flowsTo/getALocalSource
and getters likegetAMethodCall
are indexed in opposite directions:flowsTo/getALocalSource
map a node backwards to its SourceNode, whilegetAMethodCall
and friends map a SourceNode forwards to its use sites. It's worth keeping this in mind as the following two lines are not performance-equivalent:^ @erik-krogh @esbena worth keeping in mind as rewrites like this may in theory cause/resolve performance issues.
Evaluations: