Minify the shadowed JAR with R8 - #669
Conversation
Goooler
commented
Aug 12, 2026
```
OLD: old.jar
NEW: new.jar
│ compressed │ uncompressed
├────────────┬────────────┬─────────────┼────────────┬───────────┬─────────────
JAR │ old │ new │ diff │ old │ new │ diff
───────┼────────────┼────────────┼─────────────┼────────────┼───────────┼─────────────
class │ 66.07 MiB │ 14.71 MiB │ -51.36 MiB │ 167.93 MiB │ 29.43 MiB │ -138.5 MiB
other │ 996.67 KiB │ 829.11 KiB │ -167.56 KiB │ 2.03 MiB │ 1.94 MiB │ -86.02 KiB
───────┼────────────┼────────────┼─────────────┼────────────┼───────────┼─────────────
total │ 67.04 MiB │ 15.52 MiB │ -51.52 MiB │ 169.96 MiB │ 31.37 MiB │ -138.59 MiB
CLASSES │ old │ new │ diff
─────────┼────────┼───────┼────────────────────────
classes │ 32906 │ 10526 │ -22380 (+1 -22381)
methods │ 309307 │ 74531 │ -234776 (+268 -235044)
fields │ 78688 │ 23174 │ -55514 (+12 -55526)
```
|
Just a quick note: we don't need to merge this for now. The main purpose here is to show the difference between the before and after. #584 has been merged for minification and to provide a binary JAR. It should be a better replacement for this version. |
```
bloaty -d symbols ktfmt-native-old -- ktfmt-native-new
FILE SIZE VM SIZE
-------------- --------------
+8.5% +2.12Mi +8.5% +2.12Mi [__DATA,__svm_heap]
+6.1% +193Ki +6.1% +193Ki ___svm_code_section
+2.4% +11.9Ki +3.2% +16.0Ki [__LINKEDIT]
+428% +1.34Ki +428% +1.34Ki [__DATA,__data]
+4.4% +720 +4.4% +720 [__TEXT]
+2.5% +96 +2.5% +96 _sbom
-0.4% -96 -0.2% -96 [__DATA]
-44.3% -1.34Ki -44.3% -1.34Ki _sbom_length
-5.1% -1.03Mi -5.1% -1.03Mi _IsolateEnterStub__JavaMainWrapper__run__cXbfAhOWcF90761nQYco7L
+2.6% +1.29Mi +2.7% +1.30Mi TOTAL
```
|
BTW, I fed the output of the shadowed JAR into the native image input and the final binary size was reduced slightly. |
| Metric | Before (`c36cc47`) | After (`cf41522`) | Difference | Change (%) | | :--- | :--- | :--- | :--- | :--- | | **Compressed JAR Size** | 15.52 MiB | **14.91 MiB** | **-626.94 KiB** | **-3.96%** | | **Uncompressed Size** | 31.37 MiB | **29.88 MiB** | **-1.49 MiB** | **-4.75%** | | **Total Classes** | 10,526 | **10,223** | **-303** | **-2.88%** | | **Total Methods** | 74,531 | **70,771** | **-3,760** | **-5.04%** | | **Total Fields** | 23,174 | **22,715** | **-459** | **-1.98%** | | Segment / Symbol | File Size Diff | VM Size Diff | Change (%) | | :--- | :--- | :--- | :--- | | `[__DATA,__data]` | +544 B | +544 B | +48.0% | | `[__TEXT]` | +176 B | +176 B | +1.1% | | `_sbom` | +24 B | +24 B | +0.7% | | `[__DATA]` | -24 B | -24 B | -0.1% | | `_IsolateEnterStub__JavaMainWrapper...` | -176 B | -176 B | -0.0% | | `_sbom_length` | -544 B | -544 B | -23.9% | | **TOTAL** | **0 B** | **0 B** | **0.0%** |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
This is really nice improvement, thanks for submitting the PR. I noticed you did not update the |
|
I sent this to demonstrate a potential use case, but I don't have a strong opinion on whether it should be merged. Because there are so many cases that can't be covered by the current tests. I would prefer closing this or holding it. |
|
I think its worthwhile to do (I contributed this feature to shadow!) and it's doable to make a custom Test task that tests with this minified jar. I do think it shouldn't be obfuscated though, as that'll make bugs nigh-impossible to report for users. I don't know how this would interact with native image though, it may require a bit more work |