You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference-manual/native-image/guides/optimize-file-size.md
+10-3Lines changed: 10 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ For the demo, run a "fortune teller" application that simulates the traditional
46
46
47
47
3. Check the file size which should be around 13M:
48
48
```bash
49
-
du -sh target/fortune*
49
+
du -h target/fortune
50
50
```
51
51
52
52
## Build a Native Executable Optimized for Size
@@ -88,8 +88,15 @@ Next create a native executable with the size optimization on, giving a differen
88
88
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.
89
89
90
90
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"}.
93
100
94
101
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).
0 commit comments