Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add a new benchmark example to characterise multi-component performance #1326

Merged
merged 9 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pull_request_rules:
conditions:
- status-success=bench-example (8.10.4, ubuntu-latest, Cabal-3.0.0.0)
- status-success=bench-example (8.10.4, ubuntu-latest, lsp-types-1.0.0.1)
# disabled (too slow, ~4h) until hie-bios >0.7.2 is released
# - status-success=bench-example (8.10.4, ubuntu-latest, bench_example_HLS)

- status-success=nix (default, ubuntu-latest)
- status-success=nix (default, macOS-latest)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ jobs:
matrix:
ghc: ['8.10.4']
os: [ubuntu-latest]
example: ['Cabal-3.0.0.0', 'lsp-types-1.0.0.1']
example: ['Cabal-3.0.0.0', 'lsp-types-1.0.0.1', 'bench_example_HLS']

steps:
# Cancel queued workflows from earlier commits in this branch
Expand Down
2 changes: 1 addition & 1 deletion fmt.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
set -eou pipefail
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
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
10 changes: 10 additions & 0 deletions ghcide/bench/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ examples:
modules:
- src/Language/LSP/VFS.hs
- src/Language/LSP/Types/Lens.hs
# Small but heavily multi-component example
- path: bench/example/HLS
modules:
- hls-plugin-api/src/Ide/Plugin/Config.hs
- ghcide/src/Development/IDE/Plugin/CodeAction/ExactPrint.hs
# Things get too slow with more than 2 components, hie-bios 0.7.3 will help here
# - ghcide/bench/hist/Main.hs
# - ghcide/bench/lib/Experiments/Types.hs
# - ghcide/test/exe/Main.hs
# - exe/Plugins.hs

# The set of experiments to execute
experiments:
Expand Down
1 change: 1 addition & 0 deletions ghcide/bench/example/HLS
51 changes: 27 additions & 24 deletions ghcide/bench/lib/Experiments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module Experiments
, exampleToOptions
) where
import Control.Applicative.Combinators (skipManyTill)
import Control.Exception.Safe
import Control.Exception.Safe (IOException, handleAny, try)
import Control.Monad.Extra
import Control.Monad.IO.Class
import Data.Aeson (Value(Null))
Expand All @@ -41,6 +41,7 @@ import System.FilePath ((</>), (<.>))
import System.Process
import System.Time.Extra
import Text.ParserCombinators.ReadP (readP_to_S)
import Development.Shake (cmd_, CmdOption (Cwd, FileStdout))

charEdit :: Position -> TextDocumentContentChangeEvent
charEdit p =
Expand Down Expand Up @@ -423,19 +424,24 @@ setup :: HasConfig => IO SetupResult
setup = do
-- when alreadyExists $ removeDirectoryRecursive examplesPath
benchDir <- case example ?config of
UsePackage{..} -> return examplePath
UsePackage{..} -> do
let hieYamlPath = examplePath </> "hie.yaml"
alreadyExists <- doesFileExist hieYamlPath
unless alreadyExists $
cmd_ (Cwd examplePath) (FileStdout hieYamlPath) ("gen-hie"::String)
return examplePath
GetPackage{..} -> do
let path = examplesPath </> package
package = exampleName <> "-" <> showVersion exampleVersion
hieYamlPath = path </> "hie.yaml"
alreadySetup <- doesDirectoryExist path
unless alreadySetup $
case buildTool ?config of
Cabal -> do
let cabalVerbosity = "-v" ++ show (fromEnum (verbose ?config))
callCommandLogging $ "cabal get " <> cabalVerbosity <> " " <> package <> " -d " <> examplesPath
writeFile
(path </> "hie.yaml")
("cradle: {cabal: {component: " <> exampleName <> "}}")
let hieYamlPath = path </> "hie.yaml"
cmd_ (Cwd path) (FileStdout hieYamlPath) ("gen-hie"::String)
-- Need this in case there is a parent cabal.project somewhere
writeFile
(path </> "cabal.project")
Expand Down Expand Up @@ -464,9 +470,7 @@ setup = do
]
)

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

whenJust (shakeProfiling ?config) $ createDirectoryIfMissing True
Expand Down Expand Up @@ -498,22 +502,21 @@ setupDocumentContents config =

-- Find an identifier defined in another file in this project
symbols <- getDocumentSymbols doc
case symbols of
Left [DocumentSymbol{_children = Just (List symbols)}] -> do
let endOfImports = case symbols of
DocumentSymbol{_kind = SkModule, _name = "imports", _range } : _ ->
Position (succ $ _line $ _end _range) 4
DocumentSymbol{_range} : _ -> _start _range
[] -> error "Module has no symbols"
contents <- documentContents doc

identifierP <- searchSymbol doc contents endOfImports

return $ DocumentPositions{..}
other ->
error $ "symbols: " <> show other


let endOfImports = case symbols of
Left symbols | Just x <- findEndOfImports symbols -> x
_ -> error $ "symbols: " <> show symbols
contents <- documentContents doc
identifierP <- searchSymbol doc contents endOfImports
return $ DocumentPositions{..}

findEndOfImports :: [DocumentSymbol] -> Maybe Position
findEndOfImports (DocumentSymbol{_kind = SkModule, _name = "imports", _range} : _) =
Just $ Position (succ $ _line $ _end _range) 4
findEndOfImports [DocumentSymbol{_kind = SkFile, _children = Just (List cc)}] =
findEndOfImports cc
findEndOfImports (DocumentSymbol{_range} : _) =
Just $ _start _range
findEndOfImports _ = Nothing

--------------------------------------------------------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions ghcide/ghcide.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ benchmark benchHist
other-modules: Experiments.Types
build-tool-depends:
ghcide:ghcide-bench,
hp2pretty:hp2pretty
hp2pretty:hp2pretty,
implicit-hie:gen-hie
default-extensions:
BangPatterns
DeriveFunctor
Expand Down Expand Up @@ -322,7 +323,8 @@ test-suite ghcide-tests
default-language: Haskell2010
build-tool-depends:
ghcide:ghcide,
ghcide:ghcide-test-preprocessor
ghcide:ghcide-test-preprocessor,
implicit-hie:gen-hie
build-depends:
aeson,
base,
Expand Down