Skip to content

Commit 5cfe4ec

Browse files
pepeiborrajneira
andauthored
Add a new benchmark example to characterise multi-component performance (haskell#1326)
* [ghcide-bench] handle main modules * [ghcide-bench] use gen-hie * [benchmark] Add the HLS benchmark example * Tweak down the number of components * Update mergify conditions Co-authored-by: Javier Neira <[email protected]>
1 parent b2ea71d commit 5cfe4ec

File tree

7 files changed

+46
-28
lines changed

7 files changed

+46
-28
lines changed

.github/mergify.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pull_request_rules:
77
conditions:
88
- status-success=bench-example (8.10.4, ubuntu-latest, Cabal-3.0.0.0)
99
- status-success=bench-example (8.10.4, ubuntu-latest, lsp-types-1.0.0.1)
10+
# disabled (too slow, ~4h) until hie-bios >0.7.2 is released
11+
# - status-success=bench-example (8.10.4, ubuntu-latest, bench_example_HLS)
1012

1113
- status-success=nix (default, ubuntu-latest)
1214
- status-success=nix (default, macOS-latest)

.github/workflows/bench.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
matrix:
8282
ghc: ['8.10.4']
8383
os: [ubuntu-latest]
84-
example: ['Cabal-3.0.0.0', 'lsp-types-1.0.0.1']
84+
example: ['Cabal-3.0.0.0', 'lsp-types-1.0.0.1', 'bench_example_HLS']
8585

8686
steps:
8787
# Cancel queued workflows from earlier commits in this branch

fmt.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22
set -eou pipefail
3-
curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s ghcide/src ghcide/exe ghcide/bench shake-bench/src ghcide/test/exe --with-group=extra --hint=ghcide/.hlint.yaml
3+
curl -sSL https://raw.github.com/ndmitchell/hlint/master/misc/run.sh | sh -s ghcide/src ghcide/exe ghcide/bench/lib ghcide/bench/exe ghcide/bench/hist shake-bench/src ghcide/test/exe --with-group=extra --hint=ghcide/.hlint.yaml

ghcide/bench/config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ examples:
2323
modules:
2424
- src/Language/LSP/VFS.hs
2525
- src/Language/LSP/Types/Lens.hs
26+
# Small but heavily multi-component example
27+
- path: bench/example/HLS
28+
modules:
29+
- hls-plugin-api/src/Ide/Plugin/Config.hs
30+
- ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs
31+
# Things get too slow with more than 2 components, hie-bios 0.7.3 will help here
32+
# - ghcide/bench/hist/Main.hs
33+
# - ghcide/bench/lib/Experiments/Types.hs
34+
# - ghcide/test/exe/Main.hs
35+
# - exe/Plugins.hs
2636

2737
# The set of experiments to execute
2838
experiments:

ghcide/bench/example/HLS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../..

ghcide/bench/lib/Experiments.hs

+27-24
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Experiments
2020
, exampleToOptions
2121
) where
2222
import Control.Applicative.Combinators (skipManyTill)
23-
import Control.Exception.Safe
23+
import Control.Exception.Safe (IOException, handleAny, try)
2424
import Control.Monad.Extra
2525
import Control.Monad.IO.Class
2626
import Data.Aeson (Value(Null))
@@ -41,6 +41,7 @@ import System.FilePath ((</>), (<.>))
4141
import System.Process
4242
import System.Time.Extra
4343
import Text.ParserCombinators.ReadP (readP_to_S)
44+
import Development.Shake (cmd_, CmdOption (Cwd, FileStdout))
4445

4546
charEdit :: Position -> TextDocumentContentChangeEvent
4647
charEdit p =
@@ -423,19 +424,24 @@ setup :: HasConfig => IO SetupResult
423424
setup = do
424425
-- when alreadyExists $ removeDirectoryRecursive examplesPath
425426
benchDir <- case example ?config of
426-
UsePackage{..} -> return examplePath
427+
UsePackage{..} -> do
428+
let hieYamlPath = examplePath </> "hie.yaml"
429+
alreadyExists <- doesFileExist hieYamlPath
430+
unless alreadyExists $
431+
cmd_ (Cwd examplePath) (FileStdout hieYamlPath) ("gen-hie"::String)
432+
return examplePath
427433
GetPackage{..} -> do
428434
let path = examplesPath </> package
429435
package = exampleName <> "-" <> showVersion exampleVersion
436+
hieYamlPath = path </> "hie.yaml"
430437
alreadySetup <- doesDirectoryExist path
431438
unless alreadySetup $
432439
case buildTool ?config of
433440
Cabal -> do
434441
let cabalVerbosity = "-v" ++ show (fromEnum (verbose ?config))
435442
callCommandLogging $ "cabal get " <> cabalVerbosity <> " " <> package <> " -d " <> examplesPath
436-
writeFile
437-
(path </> "hie.yaml")
438-
("cradle: {cabal: {component: " <> exampleName <> "}}")
443+
let hieYamlPath = path </> "hie.yaml"
444+
cmd_ (Cwd path) (FileStdout hieYamlPath) ("gen-hie"::String)
439445
-- Need this in case there is a parent cabal.project somewhere
440446
writeFile
441447
(path </> "cabal.project")
@@ -464,9 +470,7 @@ setup = do
464470
]
465471
)
466472

467-
writeFile
468-
(path </> "hie.yaml")
469-
("cradle: {stack: {component: " <> show (exampleName <> ":lib") <> "}}")
473+
cmd_ (Cwd path) (FileStdout hieYamlPath) ("gen-hie"::String) ["--stack"::String]
470474
return path
471475

472476
whenJust (shakeProfiling ?config) $ createDirectoryIfMissing True
@@ -498,22 +502,21 @@ setupDocumentContents config =
498502

499503
-- Find an identifier defined in another file in this project
500504
symbols <- getDocumentSymbols doc
501-
case symbols of
502-
Left [DocumentSymbol{_children = Just (List symbols)}] -> do
503-
let endOfImports = case symbols of
504-
DocumentSymbol{_kind = SkModule, _name = "imports", _range } : _ ->
505-
Position (succ $ _line $ _end _range) 4
506-
DocumentSymbol{_range} : _ -> _start _range
507-
[] -> error "Module has no symbols"
508-
contents <- documentContents doc
509-
510-
identifierP <- searchSymbol doc contents endOfImports
511-
512-
return $ DocumentPositions{..}
513-
other ->
514-
error $ "symbols: " <> show other
515-
516-
505+
let endOfImports = case symbols of
506+
Left symbols | Just x <- findEndOfImports symbols -> x
507+
_ -> error $ "symbols: " <> show symbols
508+
contents <- documentContents doc
509+
identifierP <- searchSymbol doc contents endOfImports
510+
return $ DocumentPositions{..}
511+
512+
findEndOfImports :: [DocumentSymbol] -> Maybe Position
513+
findEndOfImports (DocumentSymbol{_kind = SkModule, _name = "imports", _range} : _) =
514+
Just $ Position (succ $ _line $ _end _range) 4
515+
findEndOfImports [DocumentSymbol{_kind = SkFile, _children = Just (List cc)}] =
516+
findEndOfImports cc
517+
findEndOfImports (DocumentSymbol{_range} : _) =
518+
Just $ _start _range
519+
findEndOfImports _ = Nothing
517520

518521
--------------------------------------------------------------------------------------------
519522

ghcide/ghcide.cabal

+4-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ benchmark benchHist
226226
other-modules: Experiments.Types
227227
build-tool-depends:
228228
ghcide:ghcide-bench,
229-
hp2pretty:hp2pretty
229+
hp2pretty:hp2pretty,
230+
implicit-hie:gen-hie
230231
default-extensions:
231232
BangPatterns
232233
DeriveFunctor
@@ -322,7 +323,8 @@ test-suite ghcide-tests
322323
default-language: Haskell2010
323324
build-tool-depends:
324325
ghcide:ghcide,
325-
ghcide:ghcide-test-preprocessor
326+
ghcide:ghcide-test-preprocessor,
327+
implicit-hie:gen-hie
326328
build-depends:
327329
aeson,
328330
base,

0 commit comments

Comments
 (0)