Commit 3e41807
Optimize DevTools resource lookup performance
The resource resolver in DevTools can cause performance degradation
during application restarts in large projects. Key methods like
isDeleted() and getAdditionalResources() rely on nested loops, leading
to O(n*m) complexity.
This commit refactors ClassLoaderFiles to use a pre-computed, flattened
map. This provides O(1) complexity for direct lookups and allows for
efficient single-loop iteration.
The ClassLoaderFilesResourcePatternResolver is updated to leverage this
new, efficient structure:
- getFile() and size() are improved from O(n) to O(1).
- isDeleted() and getAdditionalResources() are improved from O(n*m) to
O(m) by eliminating nested loops.
- Data consistency is maintained across all operations.
This optimization significantly improves restart performance with a
minimal memory footprint, while preserving the existing API and
exception handling behavior.
See gh-46289
Signed-off-by: DongHoon Lee <[email protected]>1 parent 4761e13 commit 3e41807
File tree
2 files changed
+39
-34
lines changed- module/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart
- classloader
2 files changed
+39
-34
lines changedLines changed: 17 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
137 | 135 | | |
138 | 136 | | |
139 | 137 | | |
| |||
149 | 147 | | |
150 | 148 | | |
151 | 149 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
164 | 157 | | |
165 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
166 | 162 | | |
167 | 163 | | |
168 | 164 | | |
| |||
Lines changed: 22 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
49 | 55 | | |
50 | 56 | | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| 60 | + | |
54 | 61 | | |
55 | 62 | | |
56 | 63 | | |
| |||
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| 70 | + | |
63 | 71 | | |
64 | 72 | | |
65 | 73 | | |
| |||
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
| 108 | + | |
100 | 109 | | |
101 | 110 | | |
102 | 111 | | |
103 | 112 | | |
104 | 113 | | |
105 | 114 | | |
| 115 | + | |
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
| |||
128 | 138 | | |
129 | 139 | | |
130 | 140 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 141 | + | |
136 | 142 | | |
137 | 143 | | |
138 | 144 | | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
147 | 156 | | |
148 | 157 | | |
149 | 158 | | |
| |||
0 commit comments