Skip to content

Commit fa12fff

Browse files
fniephausolyagpl
authored andcommitted
Add information about build reports
1 parent de5f828 commit fa12fff

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

docs/reference-manual/native-image/guides/optimize-file-size.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ For the demo, run a "fortune teller" application that simulates the traditional
4646

4747
3. Check the file size which should be around 13M:
4848
```bash
49-
du -sh target/fortune*
49+
du -h target/fortune
5050
```
5151

5252
## Build a Native Executable Optimized for Size
@@ -88,8 +88,15 @@ Next create a native executable with the size optimization on, giving a differen
8888
How much the file size can be reduced by the `-Os` option varies between applications, and depends on how much Native Image applies inlining and other optimizations that increase size in the default `-O2` mode.
8989

9090
The build report generated in the previous step, _fortune-optimized-build-report.html_, tells exactly what was included in your native executable.
91-
It is an HTML file.
92-
You can open it in a regular web browser and examine.
91+
It is an HTML file that you can open in a regular web browser.
92+
93+
In case your native executable is quite large in file size, you may want to review the list of embedded resources, the list of modules and packages included in the code area, or the list of object types in the image heap, and check whether these elements are essential for your application.
94+
Sometimes, large files are accidentally embedded as a resource due to erroneous regular expression patterns in the resource configuration of reachability metadata.
95+
Registering wrong or too many Java types for reflection can also increase the size of a native executable significantly, by making unnecessary parts of the application, libraries, or the JDK reachable by accident.
96+
Moreover, build-time initialization, if not used towards a specific goal, can cause large Java objects such as empty caches to be accidentally included in the image heap and, thus, cause bloat in a native executable.
97+
98+
Generally, it is a good idea to check file size, number of embedded resources, or other metrics from time to time, for example, when adding or updating dependencies, or even monitor build metrics frequently.
99+
For this, you can use the [machine-readable version of the build output](../overview/BuildOutput.md#machine-readable-build-output) or the [build reports for GitHub Actions](https://medium.com/graalvm/native-image-build-reports-and-update-notifications-351aca964a55){:target="_blank"}.
93100

94101
There are other Native Image techniques that can positively affect the executable size, besides improving other metrics, for example, [Profile-Guided Optimizations (PGO)](optimize-native-executable-with-pgo.md).
95102

0 commit comments

Comments
 (0)