Skip to content

Commit e32e7d1

Browse files
committed
Remove all those custom options to reduce binary size from docs
1 parent 790d89a commit e32e7d1

File tree

1 file changed

+6
-60
lines changed

1 file changed

+6
-60
lines changed

docs/user/Native-Images-with-Python.md

Lines changed: 6 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -22,78 +22,27 @@ The created example demonstrates useful default options for the Python context,
2222
## Reducing Binary Size
2323

2424
Python is a feature-rich language with an extensive standard library.
25-
CPython's philosophy of "batteries included" means it ships with many built-in modules and libraries.
26-
As a compatible Python implementation, GraalPy includes most of these same "batteries."
27-
However, this can result in large native executables when embedding GraalPy in Java applications.
25+
This can result in large native executables when embedding GraalPy in Java applications.
2826
You can significantly reduce the size by excluding components your application doesn't need by considering what your Python code actually uses.
2927

30-
### Available Optimizations
31-
32-
GraalPy provides several system properties that exclude specific language components.
33-
When used together, these can reduce executable size by approximately 20%.
34-
35-
| Property | Removes | Size Impact | Use Case |
36-
| ----------------------------------------- | ------------------------------------------------------------ | ----------- | ------------------------------------- |
37-
| `python.WithoutSSL=true` | SSL/TLS support (`ssl` module) | **High** | No HTTPS or certificates needed |
38-
| `python.WithoutDigest=true` | Crypto hash modules (`_md5`, `_sha1`, `_sha256`, etc.) | **Medium** | No cryptographic hashing required |
39-
| `python.WithoutCompressionLibraries=true` | Compression modules (`zlib`, `lzma`, `bzip2`, `zipimporter`) | **Medium** | No compression/decompression needed |
40-
| `python.WithoutJavaInet=true` | Network socket support (`socket` module) | **Medium** | No network access required |
41-
| `python.WithoutNativePosix=true` | Native POSIX API backend | **Low** | Embedded Java-only scenarios |
42-
| `python.WithoutPlatformAccess=true` | System process access (`signal`, `subprocess`) | **Low** | Security-focused deployments |
43-
| `python.AutomaticAsyncActions=false` | Automatic async thread management | **Low** | Manual async action control |
44-
45-
## Build Configuration Examples
46-
47-
### Maven Configuration
48-
49-
To apply size optimizations in Maven, configure these build arguments to your _pom.xml_ file within the native plugin configuration:
50-
51-
```xml
52-
<plugin>
53-
<groupId>org.graalvm.buildtools</groupId>
54-
<artifactId>native-maven-plugin</artifactId>
55-
<version>0.9.28</version>
56-
<configuration>
57-
<buildArgs>
58-
<!-- Remove unused Python components for smaller size -->
59-
<buildArg>-Dpython.WithoutSSL=true</buildArg>
60-
<buildArg>-Dpython.WithoutDigest=true</buildArg>
61-
<buildArg>-Dpython.WithoutCompressionLibraries=true</buildArg>
62-
<buildArg>-Dpython.WithoutJavaInet=true</buildArg>
63-
<buildArg>-Dpython.WithoutNativePosix=true</buildArg>
64-
<buildArg>-Dpython.WithoutPlatformAccess=true</buildArg>
65-
<buildArg>-Dpython.AutomaticAsyncActions=false</buildArg>
66-
67-
<!-- Remove pre-initialized Python context -->
68-
<buildArg>-Dimage-build-time.PreinitializeContexts=</buildArg>
69-
70-
<!-- Increase memory for the build process -->
71-
<buildArg>-J-Xmx8g</buildArg>
72-
</buildArgs>
73-
</configuration>
74-
</plugin>
75-
```
76-
77-
> Note: Remove any `'-Dpython.WithoutX=true'` entries for components your application needs.
78-
79-
## Removing Pre-initialized Python Heap
28+
### Removing Pre-initialized Python Heap
8029

8130
By default, GraalPy includes a pre-initialized Python context in the executable for faster startup.
82-
However, this adds several thousand Python objects to your binary.
31+
Disabling this reduces the binary size by about 15MiB.
8332
You should remove this if:
84-
- Creating more than one context
33+
- You are creating more than one context
8534
- Binary size is more important than a slight startup delay
8635

8736
To remove the pre-initialized heap, add this flag to your build configuration:
8837

8938
```bash
90-
-Dimage-build-time.PreinitializeContexts=
39+
-Dpolyglot.image-build-time.PreinitializeContexts=
9140
```
9241

9342
### Disabling Runtime Compilation of Python Code
9443

9544
If binary size is significantly more important than execution speed, you can disable JIT compilation entirely.
96-
45+
This will reduce binary size by around 40%.
9746
You should use this if:
9847

9948
- Your Python scripts are very short-running
@@ -117,6 +66,3 @@ Since every application is different, experiment with different combinations to
11766
## Shipping Python Packages
11867

11968
Our Maven archetype by default is set up to include all needed Python files in the native binary itself, so the image is self-contained.
120-
121-
In custom embeddings, the Python standard library is copied next to the native image.
122-
When moving the native image, the standard library folder needs to be kept next to it.

0 commit comments

Comments
 (0)