Skip to content

Commit de4b55c

Browse files
authored
Merge pull request #177 from arduino/limit-concurrent-jobs
Limit parallel jobs to 1 / use in-memeory pch storage
2 parents 1c2d4dd + 22c33ae commit de4b55c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Diff for: ls/ls.go

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ type Config struct {
8080
EnableLogging bool
8181
SkipLibrariesDiscoveryOnRebuild bool
8282
DisableRealTimeDiagnostics bool
83+
Jobs int
8384
}
8485

8586
var yellow = color.New(color.FgHiYellow)

Diff for: ls/lsp_client_clangd.go

+9
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,17 @@ func newClangdLSPClient(logger jsonrpc.FunctionLogger, dataFolder *paths.Path, l
4949
// Start clangd
5050
args := []string{
5151
"-log=verbose",
52+
"--pch-storage=memory",
5253
fmt.Sprintf(`--compile-commands-dir=%s`, ls.buildPath),
5354
}
55+
if jobs := ls.config.Jobs; jobs == -1 {
56+
// default: limit parallel build jobs to 1
57+
args = append(args, "-j", "1")
58+
} else if jobs == 0 {
59+
// no args: clangd will max out the available cores
60+
} else {
61+
args = append(args, "-j", fmt.Sprintf("%d", jobs))
62+
}
5463
if dataFolder != nil {
5564
args = append(args, fmt.Sprintf("-query-driver=%s", dataFolder.Join("packages", "**").Canonical()))
5665
}

Diff for: main.go

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func main() {
7070
noRealTimeDiagnostics := flag.Bool(
7171
"no-real-time-diagnostics", false,
7272
"Disable real time diagnostics")
73+
jobs := flag.Int("jobs", -1, "Max number of parallel jobs. Default is 1. Use 0 to match the number of available CPU cores.")
7374
flag.Parse()
7475

7576
if *loggingBasePath != "" {
@@ -141,6 +142,7 @@ func main() {
141142
CliInstanceNumber: *cliDaemonInstanceNumber,
142143
SkipLibrariesDiscoveryOnRebuild: *skipLibrariesDiscoveryOnRebuild,
143144
DisableRealTimeDiagnostics: *noRealTimeDiagnostics,
145+
Jobs: *jobs,
144146
}
145147

146148
stdio := streams.NewReadWriteCloser(os.Stdin, os.Stdout)

0 commit comments

Comments
 (0)