git.iko.soy/typeable/cabal2nix
on master help sign in
Improve memory usage of PackageMap reading

Previously, the whole output of nix-env was read in strictly before being processed. With this change, the output is now streamed to aeson, so it can be processed while it is generated, improving memory usage.

commitbadda1eb05994906083085686dbdd86f13237e41 authorBenno Fünfstück <benno.fuenfstueck@gmail.com> dateTue 18 Aug 2015, 00:19 (11 years ago) parent6e3550e
1 file changed+6−3
src/Distribution/Nixpkgs/PackageMap.hs+6−3
src/Distribution/Nixpkgs/PackageMap.hs+6−3
@@ -1,12 +1,12 @@
11module Distribution.Nixpkgs.PackageMap where
22
33import qualified Data.Aeson as JSON
4+import qualified Data.ByteString.Lazy as LBS
45import Data.List.Split
56import qualified Data.Map as Map
67import Data.Map.Strict ( Map )
78import Data.Set ( Set )
89import qualified Data.Set as Set
9−import qualified Data.String.UTF8 as UTF8 ( fromString, toRep )
1010import System.Process
1111
1212type Attribute = String
@@ -14,9 +14,12 @@ type Path = [Attribute]
1414
1515readNixpkgAttributeSet :: FilePath -> IO (Set Attribute)
1616readNixpkgAttributeSet nixpkgs = do
17− buf <- readProcess "nix-env" ["-qaP", "--json", "-f"++nixpkgs] ""
17+ (_, Just h, _, _) <- createProcess (proc "nix-env" ["-qaP", "--json", "-f"++nixpkgs])
18+ { std_out = CreatePipe
19+ }
20+ buf <- LBS.hGetContents h
1821 let pkgmap :: Either String (Map Attribute JSON.Object)
19− pkgmap = JSON.eitherDecodeStrict (UTF8.toRep (UTF8.fromString buf))
22+ pkgmap = JSON.eitherDecode buf
2023 either fail (return . Map.keysSet) pkgmap
2124
2225parsePackage :: Attribute -> (Attribute, Path)