smacker / go-tree-sitter

Golang bindings for tree-sitter https://github.com/tree-sitter/tree-sitter
MIT License
447 stars 124 forks source link

Save a tiny bit of memory by rearranging fields; also using the newer way to "unsafely" instantiate a slice: #150

Open alexaandru opened 9 months ago

alexaandru commented 9 months ago

By rearranging the fields the memory usage per type was reduced as follows:

In practice, unless you capture the matches for the entire tree at once (AND the tree is large) there won't be any difference. However, typically you'd use cursor.SetPointRange() and focus on a particular area of the tree, so these savings won't be observed in practice unless somehow you are creating lots of QueryCapture and QueryMatch nodes.

Oh, and also added a TODO note, there's something in there that looks out of place and needs to be investigated further (a useless break statement).