Skip to content

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Apr 26, 2021

This PR moves the burden of caching just the right predicates from the language-specific implementations into the shared data-flow library. It comes at the cost that we may cache some predicates that are normally trivial to compute, but I think that is outweighed by moving the caching responsibility into shared library. And even though some predicates are quite fast to compute, it may still be a win as the number of data-flow queries increase.

Project D0(s) D1(s) D1/D0
g/dotnet/efcore 2327 2405 1.03352
g/mono/mono 7460 7392 0.99088
g/rapPayne/WebGoat.Net 219 217 0.99087
g/DeafLight/SilentLux.AutoFixture.Moq.Xunit2 407 403 0.99017
g/dotnet/roslyn 2337 2291 0.98032
g/dotnet/runtime 2773 2709 0.97692
g/mcintyre321/OneOf 586 570 0.97270
g/PowerShell/PowerShell 733 711 0.96999
g/semmle/ql 389 375 0.96401
g/OrchardCMS/OrchardCore 1082 1032 0.95379
Project D0(s) D1(s) D1/D0
codeql-samate 5654 5726 1.01273
g/kamailio/kamailio 4779 4710 0.98556
g/abseil/abseil-cpp 163 161 0.98773
g/php/php-src 1112 1097 0.98651
g/torvalds/linux 4179 4057 0.97081
g/microsoft/ChakraCore 1695 1636 0.96519
g/wireshark/wireshark 5712 5474 0.95833
g/vim/vim 527 507 0.96205
g/facebook/yoga 78 75 0.96154
g/boostorg/boost 1129 1082 0.95837
g/git/git 509 487 0.95678
g/openjdk/jdk 2455 2333 0.95031
g/an-tao/drogon 339 321 0.94690
g/nlohmann/json 459 434 0.94553
Project D0(s) D1(s) D1/D0
g/AdoptOpenJDK/openjdk-jdk11u 5361 5134 0.95766
g/geogebra/geogebra 1598 1503 0.94055
g/apache/pig 529 488 0.92250
g/apache/commons-io 86 79 0.91860
g/clojure/clojure 102 92 0.90196
g/apache/geode 1168 1049 0.89812
g/apache/lucene-solr 1773 1580 0.89114
g/DrJavaAtRice/drjava 162 144 0.88889
g/apache/hadoop-common 1253 1089 0.86911
Project D0(s) D1(s) D1/D0
g/openstack/nova 2297 2309 1.00522
g/saltstack/salt 2073 2075 1.00096
g/pallets/flask 470 471 1.00213
g/django/django 1079 1072 0.99351
g/FreeCAD/FreeCAD 4710 4605 0.97771
g/ytdl-org/youtube-dl 461 446 0.96746
g/python/cpython 1894 1826 0.96410

@hvitved hvitved force-pushed the dataflow/aggressive-caching branch 5 times, most recently from 6af292c to 6af0c0d Compare April 27, 2021 12:55
@hvitved hvitved force-pushed the dataflow/aggressive-caching branch from 6af0c0d to 8074e13 Compare April 27, 2021 17:07
@hvitved hvitved force-pushed the dataflow/aggressive-caching branch from 8074e13 to c35a2b9 Compare April 28, 2021 12:52
@hvitved hvitved marked this pull request as ready for review April 29, 2021 14:14
@hvitved hvitved requested review from a team as code owners April 29, 2021 14:14
@hvitved hvitved added the no-change-note-required This PR does not need a change note label Apr 29, 2021
@hvitved hvitved removed the request for review from a team April 29, 2021 14:15
@smowton
Copy link
Contributor

smowton commented Apr 29, 2021

For us to evaluate this vs. Go we'll need to bring ourselves up to date with the recent dataflow changes first. I wouldn't block this on our review.

@jbj
Copy link
Contributor

jbj commented May 3, 2021

This looks like a clear overall win for C++ on the whole suite, although it comes at the cost of slowdowns in the first query to use IR data flow (TaintedPath.ql +87s) and the first query to use AST data flow (NonConstantFormat.ql +24s). I haven't investigated the reason for this, but if we can't have the best of both worlds then it's probably best to speed up the suite as a whole.

@tamasvajk tamasvajk self-assigned this May 3, 2021
@owen-mc
Copy link
Contributor

owen-mc commented May 10, 2021

I've updated Go's dataflow libraries to match main and I've started a dist-compare testing the effect of this PR.

@hvitved
Copy link
Contributor Author

hvitved commented May 10, 2021

I've updated Go's dataflow libraries to match main and I've started a dist-compare testing the effect of this PR.

Thanks.

* The value of a parameter at function entry, viewed as a node in a data
* flow graph.
*/
class ParameterNodeExt extends Node {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not particularly happy with the introduction of ParameterNodeExt and ArgumentNodeExt as cached aliases. I think we should rename these cached versions to ParameterNode and ArgumentNode and ensure that these cached versions get suitable public scope exposure to make them appear as DataFlow::ParameterNode and DataFlow::ArgumentNode instead of the current ones.
The language-specific definitions with those names then need to be dealt with in some way. Either hidden away in some module to ensure we don't get name clashes, or renamed, or replaced by predicates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only problem with that is that languages may want to have more specific QL doc. Also, languages may want to add more predicates, for example in C# we have a ParameterNode::getParameter() predicate. Lastly, C# does not expose ArgumentNode.

Would it help if we renamed them to ParameterNodeCached and ArgumentNodeCached? (I know that the Ext naming is not good, but I wanted to keep it short.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Right. How about this, then: Import the language-specific classes and predicates qualified so we can reuse the names for the cached aliases. That also has the side-effect that we don't accidentally refer to the non-cached version inside the dataflow library.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would also allow us to reuse the names for all the predicates that currently use the Cached postfix.

@github github deleted a comment May 10, 2021
@owen-mc
Copy link
Contributor

owen-mc commented May 11, 2021

Here are the Go results (scroll right to see the last column). They generally look very good, except the 1% increase in time for Kubernetes.

Project 6f0636076f6@1f9097430 6f0636076f6@f0b7f297a time
gostats 15 13 0.866667
archiver 17 15 0.882353
prototool 32 29 0.90625
pam-ussh 11 10 0.909091
hydra_7f50b944ea7a0bc02f37a08c860670bd33453986 34 31 0.911765
hydra_9b5bbd48a72096930af08402c5e07fce7dd770f3 34 31 0.911765
ringpop-go 25 23 0.92
goruntime 13 12 0.923077
gojenkins 14 13 0.928571
sqlx 14 13 0.928571
arachne 15 14 0.933333
concourse_091671e19b3779e439f5ad4a6b4b89aa20a33778 137 128 0.934307
cherami-client-go 16 15 0.9375
storagetapper 32 30 0.9375
gobot_9a9d580de37056c636751930c9b33c03c294d3a9 49 46 0.938776
astro 17 16 0.941176
orangeforum_1f6313cb3a1e755880fc1354f3e1efc4dd2dd4aa 18 17 0.944444
orangeforum_3f73f963cdf0b9093877711f0d84ff091683e452 18 17 0.944444
plugins 18 17 0.944444
zanzibar 150 142 0.946667
concourse_dc3d15ab6c3a69890c9985f9c875d4c2949be727 132 125 0.94697
gogs_c9bb33afc3ae35db21b26fd914bd80ca277a4e0d 76 72 0.947368
client-go_689d090711762a4ab315320d706d3c9e3b225d3d 97 92 0.948454
concourse_38cb4cc025e5ed28764b4adc363a0bbf41f3c7cb 137 130 0.948905
go-jose_789a4c4bd4c118f7564954f441b29c153ccd6a96 20 19 0.95
tchannel-go 40 38 0.95
gorm 21 20 0.952381
aresdb 107 102 0.953271
sourcegraph_bde46f4ae891ca5bccaab042cab8fa72f6c2b165 159 152 0.955975
go-blessclient 23 22 0.956522
cadence 486 465 0.95679
terraform 165 158 0.957576
client-go_66e83da33c604751671a39f929644b8f471e5cd9 95 91 0.957895
flytestdlib 24 23 0.958333
spark-on-k8s-operator 24 23 0.958333
gobot_9b97c70ca6bed3ef922d8e43a01e4524e956a04a 49 47 0.959184
beego 74 71 0.959459
gogs_1f247cf8139cb483276cd8dd06385a800ce9d4b2 75 72 0.96
source-to-image 27 26 0.962963
tilt 55 53 0.963636
aws-sdk-go 1465 1413 0.964505
nomad 244 236 0.967213
sourcegraph_2555ef0e46d4b0c457cb1894d63773af48821388 162 157 0.969136
image_a3d69a4a89244803d2f5350aca6dd0fcbe444551 33 32 0.969697
makisu 33 32 0.969697
cherami-server 73 71 0.972603
rclone 227 223 0.982379
kubernetes_47063891dd782835170f500a83f37cc98c3c1013 1591 1563 0.982401
concourse_fabee1733ee9d084604c909fff2a015dcb21dd8e 130 128 0.984615
vitess 527 520 0.986717
cockroach 3433 3419 0.995922
kubernetes_7fbfe70147f963bc1fd2b0376d7efc116cc757a8 1587 1581 0.996219
assume-role-cli 14 14 1
authenticator 25 25 1
cadvisor 33 33 1
carbonserver 13 13 1
carbonzipper 15 15 1
cni-ipvlan-vpc-k8s 18 18 1
dns_833bf76c282d338e307ff7ec181b95cfc117deb2 34 34 1
go-jose_d00415a0a4fdbcfbdf69deae1fe07fc953d9e76d 20 20 1
go-torch 11 11 1
go_reuseport 10 10 1
gonduit 12 12 1
image_8ad47b442feae0a21bff51a6058227fa1e45bb41 33 33 1
kiam 22 22 1
lyft-go-samples 12 12 1
lyft-go-sdk 13 13 1
ngrok 41 41 1
oauth2_proxy_289a6ccf463a425c7606178c510fc5eeb9c8b050 19 19 1
oauth2_proxy_712739f7775378d39b8a6f6c8051188962062e9b 19 19 1
protoc-gen-star 18 18 1
tcheck 11 11 1
thrift_264a3f318ed3e9e51573f67f963c8509786bcec2 22 22 1
uberalls 12 12 1
kubernetes 781 791 1.0128
dns_501e858f679edecd4a38a86317ce50271014a80d 33 34 1.0303
thrift_6e5c0f6e315ea1cd8526789558bfd10d6cee2173 21 22 1.04762
carbonapi 29 31 1.06897
smokescreen 11 12 1.09091

@hvitved
Copy link
Contributor Author

hvitved commented May 11, 2021

Here are the Go results (scroll right to see the last column). They generally look very good, except the 1% increase in time for Kubernetes.

That's great. Once this PR is merged, you should no longer need to cache this predicate: https://github.com/github/codeql-go/blob/main/ql/src/semmle/go/dataflow/internal/DataFlowPrivate.qll#L240

@aschackmull aschackmull merged commit 74ae2e0 into github:main May 12, 2021
@hvitved hvitved deleted the dataflow/aggressive-caching branch May 12, 2021 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# C++ Java no-change-note-required This PR does not need a change note Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants