tree-sitter / tree-sitter-cli

CLI tool for creating and testing tree-sitter parsers
MIT License
45 stars 15 forks source link

Make it easy to profile parsing #7

Closed maxbrunsfeld closed 8 years ago

maxbrunsfeld commented 8 years ago
$ cd tree-sitter-javascript
$ tree-sitter parse /tmp/jquery.js --profile --repeat=10

# Opens this flame graph in a web browser:

profile-output

One useful finding from this is that the recursive functions ts_tree_assign_parents and ts_tree_release can use a lot of stack frames (I cut off the top of the graph to make it fit better here). This is probably a security risk for the library. Those functions probably need to be optimized in that regard.

maxbrunsfeld commented 8 years ago

Also, this makes it easy to see that LR parsing time is pretty much linear in the length of the input:

# repeat jquery.js 10 times
$ for i in $(seq 1 10); do cat /tmp/jquery.js >> /tmp/jquery-x10.js; done

# repeat jquery.js 100 times
$ for i in $(seq 1 100); do cat /tmp/jquery.js >> /tmp/jquery-x100.js; done

# parse the three files
$ tree-sitter parse /tmp/jquery.js
Parsed in 45 milliseconds

$ tree-sitter parse /tmp/jquery-x10.js
Parsed in 407 milliseconds

$ tree-sitter parse /tmp/jquery-x100.js
Parsed in 4144 milliseconds