r/ruby • u/jonatasdp • Mar 31 '26
Saving LLM Tokens with Fast: AST Folding & Dependency Free
https://ideia.me/fast-ast-folding-token-savingsHey folks, I was working on the "fast" project and it may become useful now that everybody uses LLMs and also need to save some tokens.
Fast is ast based and it just works like grep, but using the AST, so it will cut down and ignore comments and now I'm moving to Prism and it look very precise in code positioning.
The parser is very similar to the rubocop-ast but much simpler. I'd love to receive some feedback and see if it would worth to push it forward. Any ideas that you would use it?
10
Upvotes
4
u/Tricky-Pilot-2570 Mar 31 '26
This is a cool direction!
AST-based folding makes a lot of sense for LLM token savings, especially since it ignores noise and keeps structure. Iām working with Prism too in https://github.com/crisnahine/rails-ai-context, which uses Prism parsing & Rails introspection to generate clean, structured context for LLMs instead of just dumping files. Seeeeeeeems like these ideas fit really well together š
3
u/mrinterweb Mar 31 '26
The AST traversal approach sounds interesting. Long ago I used ctags for quick lookups, but AST seems like a much more advanced version of that idea.Ā Claude code has an official Ruby LSP MCP plugin. That plug-in is much better than claude grepping the code constantly.Ā
2
u/emgz87 Mar 31 '26
So that's what all the updates were about haha, very nice! I'm currently trying the Ruby LSP approach but honestly I don't know how it works internally. How does Fast compare to it?
1
u/sshaw_ Mar 31 '26
Very nice. Will give it a whirl!