Skip to content

Commit 790afc6

Browse files
authored
[ghcide-bench] Support extra args in examples (#2107)
* [ghcide-bench] Support extra args in examples This is useful in the context of #2060 to compare performance with and without reactive change tracking * Fix bench.yml CI script
1 parent 38b6332 commit 790afc6

File tree

5 files changed

+57
-42
lines changed

5 files changed

+57
-42
lines changed

.github/workflows/bench.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ jobs:
108108
matrix:
109109
ghc: ['8.10.4']
110110
os: [ubuntu-latest]
111-
example: ['Cabal-3.0.0.0', 'lsp-types-1.0.0.1']
111+
example: ['cabal', 'lsp-types']
112112

113113
steps:
114114
- if: ${{ needs.pre_job.outputs.should_skip != 'true' }}

ghcide/bench/config.yaml

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ outputFolder: bench-results
1212
# or a local project (path) with a valid `hie.yaml` file
1313
examples:
1414
# Medium-sized project without TH
15-
- name: Cabal
15+
- name: cabal
16+
package: Cabal
1617
version: 3.0.0.0
1718
modules:
1819
- Distribution/Simple.hs
1920
- Distribution/Types/Module.hs
21+
extra-args: [] # extra ghcide command line args
2022
# Small-sized project with TH
2123
- name: lsp-types
24+
package: lsp-types
2225
version: 1.0.0.1
2326
modules:
2427
- src/Language/LSP/VFS.hs
2528
- src/Language/LSP/Types/Lens.hs
29+
extra-args: [] # extra ghcide command line args
2630
# Small but heavily multi-component example
2731
# Disabled as it is far to slow. hie-bios >0.7.2 should help
28-
# - path: bench/example/HLS
32+
# - name: HLS
33+
# path: bench/example/HLS
2934
# modules:
3035
# - hls-plugin-api/src/Ide/Plugin/Config.hs
3136
# - ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs

ghcide/bench/hist/Main.hs

+5-6
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ import Data.Yaml (FromJSON (..), decodeFileThrow)
5050
import Development.Benchmark.Rules
5151
import Development.Shake
5252
import Development.Shake.Classes
53-
import Experiments.Types (Example, exampleToOptions)
54-
import qualified Experiments.Types as E
53+
import Experiments.Types (Example (exampleName),
54+
exampleToOptions)
5555
import GHC.Generics (Generic)
5656
import Numeric.Natural (Natural)
5757
import System.Console.GetOpt
@@ -68,7 +68,7 @@ configOpt = Option [] ["config"] (ReqArg Right configPath) "config file"
6868
readConfigIO :: FilePath -> IO (Config BuildSystem)
6969
readConfigIO = decodeFileThrow
7070

71-
instance IsExample Example where getExampleName = E.getExampleName
71+
instance IsExample Example where getExampleName = exampleName
7272
type instance RuleResult GetExample = Maybe Example
7373
type instance RuleResult GetExamples = [Example]
7474

@@ -170,11 +170,10 @@ benchGhcide samples buildSystem args BenchProject{..} = do
170170
"--samples=" <> show samples,
171171
"--csv=" <> outcsv,
172172
"--ghcide=" <> exePath,
173-
"--ghcide-options=" <> unwords exeExtraArgs,
174173
"--select",
175174
unescaped (unescapeExperiment experiment)
176175
] ++
177-
exampleToOptions example ++
176+
exampleToOptions example exeExtraArgs ++
178177
[ "--stack" | Stack == buildSystem
179178
]
180179

@@ -187,6 +186,6 @@ warmupGhcide buildSystem exePath args example = do
187186
"--ghcide=" <> exePath,
188187
"--select=hover"
189188
] ++
190-
exampleToOptions example ++
189+
exampleToOptions example [] ++
191190
[ "--stack" | Stack == buildSystem
192191
]

ghcide/bench/lib/Experiments.hs

+19-12
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,23 @@ configP =
239239
<*> optional (option auto (long "samples" <> metavar "NAT" <> help "override sampling count"))
240240
<*> strOption (long "ghcide" <> metavar "PATH" <> help "path to ghcide" <> value "ghcide")
241241
<*> option auto (long "timeout" <> value 60 <> help "timeout for waiting for a ghcide response")
242-
<*> ( GetPackage <$> strOption (long "example-package-name" <> value "Cabal")
242+
<*> ( Example "name"
243+
<$> (Right <$> packageP)
243244
<*> (some moduleOption <|> pure ["Distribution/Simple.hs"])
244-
<*> option versionP (long "example-package-version" <> value (makeVersion [3,4,0,0]))
245+
<*> pure []
245246
<|>
246-
UsePackage <$> strOption (long "example-path")
247-
<*> some moduleOption
248-
)
247+
Example "name"
248+
<$> (Left <$> pathP)
249+
<*> some moduleOption
250+
<*> pure [])
249251
where
250252
moduleOption = strOption (long "example-module" <> metavar "PATH")
251253

254+
packageP = ExamplePackage
255+
<$> strOption (long "example-package-name" <> value "Cabal")
256+
<*> option versionP (long "example-package-version" <> value (makeVersion [3,4,0,0]))
257+
pathP = strOption (long "example-path")
258+
252259
versionP :: ReadM Version
253260
versionP = maybeReader $ extract . readP_to_S parseVersion
254261
where
@@ -472,16 +479,16 @@ callCommandLogging cmd = do
472479
setup :: HasConfig => IO SetupResult
473480
setup = do
474481
-- when alreadyExists $ removeDirectoryRecursive examplesPath
475-
benchDir <- case example ?config of
476-
UsePackage{..} -> do
482+
benchDir <- case exampleDetails(example ?config) of
483+
Left examplePath -> do
477484
let hieYamlPath = examplePath </> "hie.yaml"
478485
alreadyExists <- doesFileExist hieYamlPath
479486
unless alreadyExists $
480487
cmd_ (Cwd examplePath) (FileStdout hieYamlPath) ("gen-hie"::String)
481488
return examplePath
482-
GetPackage{..} -> do
489+
Right ExamplePackage{..} -> do
483490
let path = examplesPath </> package
484-
package = exampleName <> "-" <> showVersion exampleVersion
491+
package = packageName <> "-" <> showVersion packageVersion
485492
hieYamlPath = path </> "hie.yaml"
486493
alreadySetup <- doesDirectoryExist path
487494
unless alreadySetup $
@@ -524,9 +531,9 @@ setup = do
524531

525532
whenJust (shakeProfiling ?config) $ createDirectoryIfMissing True
526533

527-
let cleanUp = case example ?config of
528-
GetPackage{} -> removeDirectoryRecursive examplesPath
529-
UsePackage{} -> return ()
534+
let cleanUp = case exampleDetails(example ?config) of
535+
Right _ -> removeDirectoryRecursive examplesPath
536+
Left _ -> return ()
530537

531538
runBenchmarks = runBenchmarksFun benchDir
532539

ghcide/bench/lib/Experiments/Types.hs

+25-21
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
module Experiments.Types (module Experiments.Types ) where
55

66
import Data.Aeson
7+
import Data.Maybe (fromMaybe)
78
import Data.Version
89
import Development.Shake.Classes
910
import GHC.Generics
1011
import Numeric.Natural
11-
import System.FilePath (isPathSeparator)
1212

1313
data CabalStack = Cabal | Stack
1414
deriving (Eq, Show)
@@ -31,40 +31,44 @@ data Config = Config
3131
}
3232
deriving (Eq, Show)
3333

34-
data Example
35-
= GetPackage {exampleName :: !String, exampleModules :: [FilePath], exampleVersion :: Version}
36-
| UsePackage {examplePath :: FilePath, exampleModules :: [FilePath]}
34+
data ExamplePackage = ExamplePackage {packageName :: !String, packageVersion :: !Version}
3735
deriving (Eq, Generic, Show)
3836
deriving anyclass (Binary, Hashable, NFData)
3937

40-
getExampleName :: Example -> String
41-
getExampleName UsePackage{examplePath} = map replaceSeparator examplePath
42-
where
43-
replaceSeparator x
44-
| isPathSeparator x = '_'
45-
| otherwise = x
46-
getExampleName GetPackage{exampleName, exampleVersion} =
47-
exampleName <> "-" <> showVersion exampleVersion
38+
data Example = Example
39+
{ exampleName :: !String
40+
, exampleDetails :: Either FilePath ExamplePackage
41+
, exampleModules :: [FilePath]
42+
, exampleExtraArgs :: [String]}
43+
deriving (Eq, Generic, Show)
44+
deriving anyclass (Binary, Hashable, NFData)
4845

4946
instance FromJSON Example where
5047
parseJSON = withObject "example" $ \x -> do
48+
exampleName <- x .: "name"
5149
exampleModules <- x .: "modules"
50+
exampleExtraArgs <- fromMaybe [] <$> x .:? "extra-args"
5251

5352
path <- x .:? "path"
5453
case path of
55-
Just examplePath -> return UsePackage{..}
54+
Just examplePath -> do
55+
let exampleDetails = Left examplePath
56+
return Example{..}
5657
Nothing -> do
57-
exampleName <- x .: "name"
58-
exampleVersion <- x .: "version"
59-
return GetPackage {..}
58+
packageName <- x .: "package"
59+
packageVersion <- x .: "version"
60+
let exampleDetails = Right ExamplePackage{..}
61+
return Example{..}
6062

61-
exampleToOptions :: Example -> [String]
62-
exampleToOptions GetPackage{..} =
63-
["--example-package-name", exampleName
64-
,"--example-package-version", showVersion exampleVersion
63+
exampleToOptions :: Example -> [String] -> [String]
64+
exampleToOptions Example{exampleDetails = Right ExamplePackage{..}, ..} extraArgs =
65+
["--example-package-name", packageName
66+
,"--example-package-version", showVersion packageVersion
67+
,"--ghcide-options", unwords $ exampleExtraArgs ++ extraArgs
6568
] ++
6669
["--example-module=" <> m | m <- exampleModules]
67-
exampleToOptions UsePackage{..} =
70+
exampleToOptions Example{exampleDetails = Left examplePath, ..} extraArgs =
6871
["--example-path", examplePath
72+
,"--ghcide-options", unwords $ exampleExtraArgs ++ extraArgs
6973
] ++
7074
["--example-module=" <> m | m <- exampleModules]

0 commit comments

Comments
 (0)