12

What does the jlink compress option do? the oracle documentation isn't very elaborated about this:

Enable compression of resources:

0: No compression
1: Constant string sharing
2: ZIP

What are the resources which getting compressed? Is there any disadvantage to --compress=2?

Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
matanper
  • 881
  • 8
  • 24
  • Good question. A lot of jlink and jmod options could benefit from an in-depth explanation, which currently those tools’ documentation lacks. – VGR Apr 16 '19 at 20:37
  • Doesn't answer but somewhat related https://stackoverflow.com/questions/48180953/what-are-the-algorithms-behind-the-level-1-and-level-2-compression-using-jlink and https://stackoverflow.com/questions/47287429/java9-packager-with-jlink-compress-tags – Naman Apr 17 '19 at 01:44

2 Answers2

13

Is there any disadvantage to --compress=2

I don't know how compress=2 internally compress modules or exactly which modules are going to compress pin pointedly, But i found this bug related to performance

Performance data/impact for users to determine what jlink optimization should be selected

--strip-debug is enabled by default in the build for JRE images, and reduces size of the runtime image (lib/modules) by ~20% (130M -> 106M) with no effect on startup

--compress=0 drops the size of lib/modules by ~30% (106M -> 69.5M), and actually seems to benefit startup in simple tests (~8 ms improvement on Hello World).

--compress=1 drops the size of lib/modules by ~54% (106M -> 49M), but comes with a penalty to startup (~8ms slowdown on Hello World)

--compress=2 drops the size of lib/modules by ~53% (106M -> 49.5M), but comes with an even greater penalty to startup (~13ms slowdown on Hello World)

In my opinion the numeric level argument to --compress is counter-intuitive and should perhaps be called out explicitly instead (--compress=strings, --compress=zip). Since it appears the two different compression strategies are working against each other it seems that perhaps they should even be mutually exclusive (remove --compress=2).

--compress=0 strikes a balance between improving startup and static footprint, --compress=1 minimizes static footprint at a small penalty to startup time.

Community
  • 1
  • 1
Ryuzaki L
  • 37,302
  • 12
  • 68
  • 98
  • alright... even the small footprint jlink only 37.7Mb.... which is still bigger for me. tough. – gumuruh Oct 18 '20 at 14:48
  • 1
    Also, `--compress=2` is counterproductive if you plan to zip your application for distribution anyway. E.g. when producing some installer .exe, the "outer" compression is more efficient for low-entropy payloads. Therefore you should avoid double-zipping – Sebastian S Aug 29 '23 at 13:41
  • My installer size actually went down 5mb, when I switched from `--compress=2` to `--compress=0`. – user38725 Sep 01 '23 at 20:27
4

This is purely based on observation. I’d love to see a more authoritative answer.

It appears the lib/modules file in the resulting image, which is some binary amalgamation of the application’s modules, is what gets compressed. I don’t know what the format of that file actually is.

I have never observed any problems with using --compress=2.

VGR
  • 40,506
  • 4
  • 48
  • 63