-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format files in parallel #1129
Format files in parallel #1129
Conversation
Thanks! I imagine you have verified that this indeed works and results in performance benefits? We have some checks on the format of the |
Not directly related to this PR, but I just got reminded that we use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments (mostly for me to look at later):
-
Support multithreading #896 (comment) talks about garbled output. We should check that, and either add some synchronization or check that
-N1
produces ungarbled output and tell users to use that if they want ungarbled output. -
There could be races here:
Lines 53 to 61 in 7a334ac
withIORefCache :: (Ord k) => IORef (Map k v) -> k -> IO v -> IO v withIORefCache cacheRef k action = do cache <- readIORef cacheRef case M.lookup k cache of Just v -> pure v Nothing -> do v <- action modifyIORef' cacheRef (M.insert k v) pure v
I think we don't need to change sth here for correctness, but there actually might be some redundant work when multiple threads try to compute the value for the same cache key?We could also move away from shared
NOINLINE
ad-hoc caches, and instead compute such data upfront (see also the last paragraph in Cache.cabal
file parsing and processing #915).
Yes, as I mentioned here I got a pretty good speedup (3x) on my usecase (formatting about 2.5k files).
Ah right, I have only been checking with
We could also just make this thread-safe by using an |
Maybe we could only do parallel processing for
We have this: ormolu/src/Ormolu/Fixity/Internal.hs Lines 275 to 276 in 7a334ac
But it is only emitted when --debug is set.
Yes 👍 |
I think it would be nice if it worked for |
Oh yeah,
Yeah, agreed, I can't imagine a use case. |
Indeed, it would be nice to have a formatter for |
43d81cb
to
2eb0ddd
Compare
I've continued to allow formatting multiple files with |
Also this should probably be documented, not sure where. |
I think we only consider the
I think it is totally fine. If anyone uses formatting through stdin on multiple files they can complain in the issue tracker. Not sure we even need to document that. |
@amesgen I think this is ready to be merged. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, two minor comments
I tested this on Agda (ie running ormolu -m check $(fd -e hs . $(nix build .#hackage.Agda --print-out-paths))
), and execution time drops from ~20s to ~7s on my machine with 8 cores 🎉
There is no explicit configuration for this, but it is possible for users to override by changing the RTS options to the `ormolu` executable.
6c577c3
to
65a9b2b
Compare
Thanks! |
Closes #1128
There is no explicit configuration for this, but it is possible for users to override by changing the RTS options to the
ormolu
executable.