Skip to content
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

Cache exposed package modules in Pantry DB #4628

Merged
merged 7 commits into from
Mar 18, 2019
Merged

Conversation

qrilka
Copy link
Contributor

@qrilka qrilka commented Mar 15, 2019

Note: Documentation fixes for https://docs.haskellstack.org/en/stable/ should target the "stable" branch, not master.

Please include the following checklist in your PR:

  • Any changes that could be relevant to users have been recorded in the ChangeLog.md
  • The documentation has been updated, if necessary.

Fixes #4536
Fixes #4624

I've switched to a script with some imports actually (otherwise there's an easy way to cheat by not getting any packages at all) :

#!/usr/bin/env stack
-- stack --resolver lts-13.0 script -v

import System.ByteOrder
import Control.Lens

main :: IO ()
main = putStrLn $ "hmm"
                  ++ ", byte order " ++ show byteOrder

And on my local machine I get the following results:

qrilka@qdesktop ~/ws/h/stack $ time stack-master script --resolver lts-13.0 hmm.hs
Using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/0.yaml specified on command line
hmm, byte order LittleEndian

real	0m4,874s
user	0m4,748s
sys	0m0,196s
qrilka@qdesktop ~/ws/h/stack $ time stack-master script --resolver lts-13.0 hmm.hs
Using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/0.yaml specified on command line
hmm, byte order LittleEndian

real	0m4,860s
user	0m4,631s
sys	0m0,300s
qrilka@qdesktop ~/ws/h/stack $ time stack script --resolver lts-13.0 hmm.hs
Using resolver: lts-13.0 specified on command line
hmm, byte order LittleEndian

real	0m0,586s
user	0m0,537s
sys	0m0,085s
qrilka@qdesktop ~/ws/h/stack $ time stack script --resolver lts-13.0 hmm.hs
Using resolver: lts-13.0 specified on command line
hmm, byte order LittleEndian

real	0m0,589s
user	0m0,550s
sys	0m0,075s
qrilka@qdesktop ~/ws/h/stack $ time stack-head script --resolver lts-13.0 hmm.hs
Using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/0.yaml specified on command line
Populating module name cache
hmm, byte order LittleEndian

real	0m5,918s
user	0m5,763s
sys	0m0,190s
qrilka@qdesktop ~/ws/h/stack $ time stack-head script --resolver lts-13.0 hmm.hs
Using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/0.yaml specified on command line
hmm, byte order LittleEndian

real	0m0,792s
user	0m0,706s
sys	0m0,134s
qrilka@qdesktop ~/ws/h/stack $ time stack-head script --resolver lts-13.0 hmm.hs
Using resolver: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/13/0.yaml specified on command line
hmm, byte order LittleEndian

real	0m0,759s
user	0m0,646s
sys	0m0,156s

Thus we get only noticeable slowdown only when there's no module cache and otherwise stack script in this PR is only marginally slower than with the stable Stack. And with #4550 resolved we could get closer to the stable version or even get faster than it.


loadExposedModulePackages
:: (HasPantryConfig env, HasLogFunc env)
=> SnapshotCacheHash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A guess would be that it would be more efficient to use SnapshotCacheId here to avoid serializing a ByteString each time.

subs/pantry/src/Pantry.hs Show resolved Hide resolved
getPackagesFromModuleNames mns = do
hash <- hashSnapshot
withSnapshotCache hash mapSnapshotPackageModules $ \getModulePackages -> do
mutableMapping <- mapMutablePackageModules
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script command does not allow for any mutable packages, so if desired for simplicity, I think you could simply add an assertion that there are no mutable packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about that, is it documented somewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, it's an implication of the requirement that there's no local config for stack script, and when I wrote that documentation, we didn't have the mutable/immutable breakdown yet.

compilerInfo <- getCompilerInfo wc
let maybePliHash dep | PLImmutable pli <- dpLocation dep =
Just $ immutableLocShaBs pli
| otherwise = Nothing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly this could be an error "No mutable packages are allowed in the `script` command


allExposedModules :: PD.GenericPackageDescription -> RIO EnvConfig [ModuleName]
allExposedModules gpd = do
-- FIXME add os, arch conditionals
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify this FIXME? It looks like you've already implemented these conditionals correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

ghcOptions = map encodeUtf8 (cpGhcOptions dpCommon)
haddocks = if cpHaddocks dpCommon then "haddocks" else ""
hash = treeKeyToBs $ locationTreeKey pli
hash = immutableLocShaBs pli
return $ B.concat ([hash, haddocks] ++ flags ++ ghcOptions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible optimization: instead of using ByteStrings here, use Builders, which will more efficiently concatenate together. May not be worth the overhead of changing things.

@qrilka
Copy link
Contributor Author

qrilka commented Mar 18, 2019

@snoyberg I think I've addressed all the points you raised

Copy link
Contributor

@snoyberg snoyberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@snoyberg snoyberg merged commit 7c08abf into master Mar 18, 2019
@snoyberg snoyberg deleted the snapshot-module-cache branch March 18, 2019 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script takes ~13x longer to start when comparing development version of stack with 1.9.3
2 participants