tree-sitter / tree-sitter

An incremental parsing system for programming tools
https://tree-sitter.github.io
MIT License
17.98k stars 1.36k forks source link

Generated parser.c very large (~25MB) #1041

Open Himujjal opened 3 years ago

Himujjal commented 3 years ago

I was writing tree-sitter-zig grammar. The generated file size is 25 MB. 25 MB is really huge for the generated C file. Even TypeScript which is a huge language, has a file size of 8.7MB.

What are the ways to optimize this?

alemuller commented 3 years ago

Based on my experience trying to reduce the size of tree-sitter-vhdl, conflicts on expression primaries and with extras rules increases the size of generated parser exponentially.

Removing primitives_type (that conflicts with identifier) from zigs grammar, reduces the size in 5 MB.

Removing multiline_string_literal (that, I think, its conflicting with extra), reduces another 7 MB.

I added $._identifier_text to word, that you already seems to have done but it isn't in the repo.

word: $ => $._identifier_text,
alemuller commented 3 years ago

Related to #693.

Himujjal commented 3 years ago

hmm. thanks for this. i will be rewriting the whole grammar from scratch using another grammar. Please can you still keep this query open?