Post

Trying some new oxlint optimizations. This PR has gone over several iterations in the last few months and the core idea is simple: don't run rules for files if they don't apply (using an AST node bitset lookup). The result: linting is around 15% faster in practice.

3 reposts39 likes

It was pretty surprising to us too, actually. I created a tool for analyzing AST node type frequencies in projects. Even in large projects, common things like import statements don't appear in ~15% of files, so we can skip import-related rules for those files. gist.github.com/camchenry/54...

gist.github.comAST Analysis of a large non-public codebase by @tomgasson, output from https://github.com/camchenry/ast-analysisAST Analysis of a large non-public codebase by @tomgasson, output from https://github.com/camchenry/ast-analysis - ast-analysis.txt

Are you running the whole visitor for each rule? In my idea you run one visitor pass, where for each node you call the rules that want to visit that node so that if no node matches the rules, it doesn't cost to have it around

Yes 😅 What you described is pretty accurate to the changes we're trying to make. We keep a mapping of (node type) -> rules so we can quickly fetch all the rules that care about that node. The main innovation is being able to quickly determine if a file contains any given node type ahead of time.

Nice! Similar to what TypeScript does too. They have "containsX" bitflags on nodes. So can skip over transformers. E.g. if the code doesn't contain any ES2020 syntax, then that transformer can be skipped entirely.

I was not aware of that, good to know! Seems like a good general optimization trick. I wonder if we could use it for our oxc transformer and minifier too.