Skip to content

Commit de3dee3

Browse files
committed
perf: parallelize user directory scanning and XML unmarshaling at startup
1 parent 4fdc1b3 commit de3dee3

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

core/src/main/java/hudson/model/User.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,32 +1124,32 @@ public static void scanAll() throws IOException {
11241124
}
11251125
var byName = instance.byName;
11261126
var idStrategy = idStrategy();
1127-
for (var dir : subdirectories) {
1127+
java.util.Arrays.stream(subdirectories).parallel().forEach(dir -> {
11281128
var dirName = dir.getName();
11291129
if (!HASHED_DIRNAMES.matcher(dirName).matches()) {
11301130
LOGGER.fine(() -> "ignoring unrecognized dir " + dir);
1131-
continue;
1131+
return;
11321132
}
11331133
var xml = new XmlFile(XSTREAM, new File(dir, CONFIG_XML));
11341134
if (!xml.exists()) {
11351135
LOGGER.fine(() -> "ignoring dir " + dir + " with no " + CONFIG_XML);
1136-
continue;
1136+
return;
11371137
}
11381138
var user = new User();
11391139
try {
11401140
xml.unmarshal(user);
11411141
} catch (Exception x) {
11421142
LOGGER.log(Level.WARNING, "failed to load " + xml, x);
1143-
continue;
1143+
return;
11441144
}
11451145
if (user.id == null) {
11461146
LOGGER.warning(() -> "ignoring " + xml + " with no <id>");
1147-
continue;
1147+
return;
11481148
}
11491149
var expectedFolderName = getUserFolderNameFor(user.id);
11501150
if (!dirName.equals(expectedFolderName)) {
11511151
LOGGER.warning(() -> "ignoring " + xml + " with <id> " + user.id + " expected to be in " + expectedFolderName);
1152-
continue;
1152+
return;
11531153
}
11541154
user.fixUpAfterLoad();
11551155
var old = byName.put(idStrategy.keyFor(user.id), user);
@@ -1158,7 +1158,7 @@ public static void scanAll() throws IOException {
11581158
} else {
11591159
LOGGER.fine(() -> "successfully loaded " + user.id + " from " + xml);
11601160
}
1161-
}
1161+
});
11621162
LOGGER.fine(() -> "loaded " + byName.size() + " entries");
11631163
}
11641164

0 commit comments

Comments
 (0)