Skip to content

Conversation

academey
Copy link

This PR removes the unused SHA-1 hash calculation from UNPACK markers in the JAR/WAR packaging process.

Current behavior:
When creating executable JARs/WARs, Spring Boot calculates a SHA-1 hash for entries that require unpacking and appends it to the entry comment as UNPACK:<hash>. However, this hash is never used - only the UNPACK: prefix is checked.

Changes made:

  • Removed SHA-1 hash calculation from StoredEntryPreparator in both BootZipCopyAction and AbstractJarWriter
  • Changed the UNPACK comment from UNPACK:<sha1-hash> to simply UNPACK:
  • Updated tests to match the new format

Performance improvement:
This eliminates unnecessary file reads during packaging. Previously, files could be read up to 3 times (CRC calculation, SHA-1 hash, and actual copying). Removing the hash calculation reduces I/O operations and memory usage, especially beneficial for large libraries.

Fixes #46183

In BootZipCopyAction and AbstractJarWriter, SHA-1 hash is calculated for
stored entries requiring unpack and set as entry comment. However, the
hash isn't used anywhere, just the marker prefix 'UNPACK:' is checked.

This commit removes the unnecessary SHA-1 hash calculation which reads
the file completely in memory, potentially three times in extreme cases.
Now the comment is simply set to 'UNPACK:' without any hash, improving
performance.

Fixes spring-projectsgh-46183

Signed-off-by: Hyunjoon Choi <hyunjoon@example.com>
Signed-off-by: academey <academey@gmail.com>
@wilkinsona
Copy link
Member

wilkinsona commented Aug 21, 2025

We should probably update the runtime side of things as well:

if (comment != null && comment.startsWith(UNPACK_MARKER)) {
return getUnpackedNestedJarUrl(jarEntry);
}

if (jarEntry.getComment().startsWith(UNPACK_MARKER)) {
return getUnpackedNestedArchive(jarEntry);
}

The startsWith check could be tightened up to equals(). We may even want to change the marker from UNPACK: to just UNPACK.

@academey please don't make any changes to the PR just yet, I'd like to discuss with the team first.

@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 21, 2025
@wilkinsona wilkinsona added this to the 4.0.x milestone Aug 21, 2025
@wilkinsona wilkinsona added the for: team-meeting An issue we'd like to discuss as a team to make progress label Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-meeting An issue we'd like to discuss as a team to make progress type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove unused SHA-1 hash from UNPACK markers of uber archive entries that require unpacking
3 participants