Skip to content

perf: reserve Vec capacities where appropriate#4571

Merged
WillLillis merged 1 commit intotree-sitter:masterfrom
WillLillis:reserved
Jul 10, 2025
Merged

perf: reserve Vec capacities where appropriate#4571
WillLillis merged 1 commit intotree-sitter:masterfrom
WillLillis:reserved

Conversation

@WillLillis
Copy link
Member

I replaced all usages Vec::new() with Vec::with_capacity() if a reasonable initial capacity (or lower bound) could be ascertained. This gives a slight speed boost in generate, for example:

tree-sitter-c (4.4%):
image
tree-sitter-ocaml (2.5%):
image
tree-sitter-javascript (2.2%):
image

@WillLillis WillLillis added perf Performance related ci:backport release-0.25 Backport label labels Jul 8, 2025
@clason
Copy link
Contributor

clason commented Jul 8, 2025

Nim and systemverilog are the worst offenders; if they get even a few percent faster, that's a win for me.

@WillLillis
Copy link
Member Author

Nim and systemverilog are the worst offenders; if they get even a few percent faster, that's a win for me.

Not much of a difference for Nim:
image
It looks like there's a boost for system verilog. Not sure why the branch misses increased, though:
image

@WillLillis WillLillis merged commit 1e7d77c into tree-sitter:master Jul 10, 2025
20 checks passed
@WillLillis WillLillis deleted the reserved branch July 10, 2025 01:46
@tree-sitter-ci-bot
Copy link

Successfully created backport PR for release-0.25:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:backport release-0.25 Backport label perf Performance related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants