Skip to content

Commit 427cdf4

Browse files
henrymercerZ80coder
authored andcommitted
JS: Update featurization for absent features optimization
Absent features are now represented implicitly by the absence of a row in the `tokenFeatures` relation, rather than explicitly by an empty string. This leads to improved runtime performance. To enable this implicit representation, we pass the set of supported token features to the `scoreEndpoints` HOP. Requires CodeQL CLI v2.7.4.
1 parent 8e1f264 commit 427cdf4

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ private module AccessPaths {
261261
}
262262

263263
/** Get a name of a supported generic token-based feature. */
264-
private string getASupportedFeatureName() {
264+
string getASupportedFeatureName() {
265265
result =
266266
[
267267
"enclosingFunctionName", "calleeName", "receiverName", "argumentIndex", "calleeApiName",
@@ -277,12 +277,5 @@ private string getASupportedFeatureName() {
277277
*/
278278
predicate tokenFeatures(DataFlow::Node endpoint, string featureName, string featureValue) {
279279
ModelScoring::endpoints(endpoint) and
280-
(
281-
if strictcount(getTokenFeature(endpoint, featureName)) = 1
282-
then featureValue = getTokenFeature(endpoint, featureName)
283-
else (
284-
// Performance note: this is a Cartesian product between all endpoints and feature names.
285-
featureValue = "" and featureName = getASupportedFeatureName()
286-
)
287-
)
280+
featureValue = getTokenFeature(endpoint, featureName)
288281
}

javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointScoring.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ module ModelScoring {
9595
}
9696

9797
predicate endpointScores(DataFlow::Node endpoint, int encodedEndpointType, float score) =
98-
scoreEndpoints(endpoints/1, requestedEndpointTypes/0, relevantTokenFeatures/3,
98+
scoreEndpoints(endpoints/1, relevantTokenFeatures/3,
99+
EndpointFeatures::getASupportedFeatureName/0, requestedEndpointTypes/0,
99100
getACompatibleModelChecksum/0)(endpoint, encodedEndpointType, score)
100101
}
101102

0 commit comments

Comments
 (0)