5 ms·
I went into one of my projects and did a `cargo fmt`, took 2.2 seconds. Dunno if that's within your tolerances or not. I personally have CI check it, rather tha
by steveklabnik 9y ago
I went into one of my projects and did a `cargo fmt`, took 2.2 seconds. Dunno if that's within your tolerances or not. I personally have CI check it, rather than on save.
- wldcordeiro 9y agocommit or push hook is nice in my opinion. Seems like a middle ground to on save and in CI.
- XR0CSWV3h3kZWg 9y agoHmm I assume that cargo fmt does it on all the files, When I wrote a lot of go I had gofmt on the write hook of my editor. It was fast enough for single files that there was never a problem. 2.2 seconds sounds rough, but if that's for lots of files it's not too much of a worry.
- RX14 9y agoI know it's fairly pointless performance bashing but I just couldn't stop myself :) # In the crystal-lang/crystal repo $ find . -name '*.cr' -print0 | wc -l --files0-from=- | tail -n 1 252745 total $ time bin/crystal tool format Using compiled compiler at `.build/crystal' bin/crystal tool format 0.62s user 0.04s system 106% cpu 0.625 total and only 48ms to formal the longest file in crystal (the parser)! Performance makes little practical difference as long as formatting a single file is fast enough to be on-save, but it does highlight the very interesting way that the crystal formatter is implemented. I'm not sure how rustfmt is implemented but crystal's formatter parses the file into the AST, and then does a single visitor pass of the file, in order, with a lexer in tow. It then basically reconstructs the entire file from scratch using the data both from the AST and the lexer (the AST visitor pass and lexer position have to be kept in sync). And surprisingly enough, this doesn't even make the formatter "too strict" in the way that it wipes out all existing style information as one would expect. It's a really cool - if a little messy - tool and one of I think my favorite parts of crystal (it doesn't have any config options either).