mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
LayersIndex.Node kept its children in a list and scanned that list linearly to find the child for each path segment. Building the index is therefore O(entries x siblings), a cost that is dominated by the largest flat directory in the jar: BOOT-INF/lib/ for the dependencies, and any bundled resource directory such as a front-end build output. Keep the children in a LinkedHashMap keyed by the segment name so that lookups are constant time. Insertion order is preserved, so the order in which buildIndex() walks the tree is unchanged. For a jar with 32,529 entries, 426 dependencies and a 12,000 file static resource directory, this reduces the number of string comparisons from 73.7M to 222K and the time spent building the index from 197ms to 12ms. For a jar with no large flat directory (20,529 entries, 426 dependencies) the gain is much smaller: 1.58M comparisons to 162K, and 12.5ms to 9.6ms. The generated layers.idx is byte for byte identical in both cases. See gh-51654 Signed-off-by: Junggi Kim <kimjg2477@gmail.com>