Skip to content

Commit 5e2fe48

Browse files
committed
[docs] Add a 'Memory usage' section to DevelopmentTips.md
1 parent 7952f05 commit 5e2fe48

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/DevelopmentTips.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ Given the size of artifacts generated, you might also want to bump the cache siz
4141
You can run some compiles to see if it is actually doing something by running `sccache --show-stats`. Depending on the exact compilation task you're running, you might see very different cache hit rates. For example, `sccache` is particularly effective if you're rebuilding LLVM, which doesn't change so frequently from the Swift compiler's perspective. On the other hand, if you're changing the compiler's AST, the cache hit rate is likely to be much lower.
4242

4343
One known issue with `sccache` is that you might occassionally get an "error: Connection to server timed out", even though you didn't stop the server. Simply re-running the build command usually works.
44+
45+
## Memory usage
46+
47+
When building Swift, peak memory usage happens during the linking phases that produce llvm and swift executables. In case your build fails because a process ran out of RAM, you can use one or more of the following techniques to reduce the peak memory usage.
48+
49+
### Reduce the amount of debug symbols
50+
51+
We can use debug symbols for only the part of the project we intend to work on. For example, when working on the compiler itself, we can build with debug symbols enabled only for the compiler:
52+
53+
```
54+
build-script --release --debug-swift
55+
```
56+
57+
### Reduce the number of parallel link jobs
58+
59+
By default, `build-script` will spawn as many parallel compile / link jobs as there are CPUs in the machine. We can reduce the number of parallel link jobs by setting the `LLVM_PARALLEL_LINK_JOBS` and `SWIFT_PARALLEL_LINK_JOBS` CMake properties. We can set them through the `--llvm-cmake-options` and `--swift-cmake-options` arguments to `build-script`.
60+
61+
For example, to have `build-script` spawn only one link job at a time, we can invoke it as:
62+
63+
```
64+
build-script --llvm-cmake-options==-DLLVM_PARALLEL_LINK_JOBS=1 --swift-cmake-options=-DSWIFT_PARALLEL_LINK_JOBS=1
65+
```

0 commit comments

Comments
 (0)