emacs-tree-sitter / tree-sitter-langs

Language bundle for Emacs's tree-sitter package
https://emacs-tree-sitter.github.io/languages/
MIT License
265 stars 132 forks source link

Optimization suggestion: Adding languages to hash table #170

Open Peter015 opened 1 year ago

Peter015 commented 1 year ago

I have noticed that the function tree-sitter-langs--init-major-mode-alist iterates through a list of major mode-language pairs and adds them to the tree-sitter-major-mode-language-alist list. I believe that for improved performance, it would be better to use a hash table instead of iterating through the list. This would allow for constant-time lookups when a buffer is opened.

I have created an implementation that replaces the list with a hash table, and would gladly open a PR. It would also be possible to set the values of the hash table instead of iterating over the list of major-mode pairs.

Please let me know your thoughts on this proposal and if there is any interest.

Thank you!

Peter015 commented 1 year ago

If there are no suggestions/thoughts on this I will open a PR on Friday to move the discussion there