Skip to content

Commit d4bb4c8

Browse files
committed
JS: Improve performance of StandardEndpointFilters::isNumeric
When looking for reads of expressions that are really variable accesses, start with the set of all variable accesses, which is a strict subset of the set of expressions, before looking at the larger set of all expressions and their underlying values. This does not yet give optimal performance, but reduces the largest bottleneck when evaluating this predicate on large databases like Node where we have ~2M variable accesses and ~10M expressions x underlying values.
1 parent 74653a8 commit d4bb4c8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

javascript/ql/lib/semmle/javascript/heuristics/SyntacticHeuristics.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ predicate isReadFrom(DataFlow::Node read, string regexp) {
2121
actualRead = read
2222
|
2323
exists(string name | name.regexpMatch(regexp) |
24-
actualRead.asExpr().getUnderlyingValue().(VarAccess).getName() = name or
25-
actualRead.(DataFlow::PropRead).getPropertyName() = name or
24+
// Performance optimisation: start with the set of variable accesses,
25+
// which is a strict subset of the set of expressions,
26+
// before looking at the larger set of all expressions and their underlying values.
27+
any(VarAccess va | pragma[only_bind_out](va) = actualRead.asExpr().getUnderlyingValue())
28+
.getName() = name
29+
or
30+
actualRead.(DataFlow::PropRead).getPropertyName() = name
31+
or
2632
actualRead.(DataFlow::InvokeNode).getCalleeName() = "get" + name
2733
)
2834
)

0 commit comments

Comments
 (0)