Reuse the extracted native library across JVMs to avoid a slow load on macOS
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 49/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- java, macos
- Ambito
- backend, performance
Direzione di ricerca
Start by reading NativeLibraryLoader and the native library extraction and loading flow; the issue does not give file paths or test names. Explore how a stable content-derived copy can be safely reused across JVMs and how a fresh copy handles an already-loaded library in the same JVM. Done means repeated JVMs can reuse the extracted library, concurrent extraction remains safe, and the existing fallback still works.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
On macOS, loading Conscrypt's native library costs about 0.6 to 0.9 s in every new JVM, and more on machines with endpoint security software. NativeLibraryLoader copies the library out of the jar into a new temp file with a random name, loads it, and deletes it. macOS checks the code signature of every binary file it has not seen before, so each JVM pays that check in dlopen. Loading a file that has been loaded before takes under 1 ms.
This adds up for test suites and build tools that start many short-lived JVMs. AlexanderGH measured it in Robolectric (robolectric/robolectric#11839): a trivial test takes 3031 ms with Conscrypt loaded the usual way and 2414 ms when Conscrypt loads a previously loaded copy of the same library. A 16 KB dylib shows the same thing:
public class T {
public static void main(String[] a) throws Exception {
java.nio.file.Path p = java.nio.file.Paths.get(a[0]);
if (a.length > 1) { // copy to a new temp file first, as Conscrypt does
java.nio.file.Path t = java.nio.file.Files.createTempFile("tiny", ".dylib");
java.nio.file.Files.copy(p, t, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
p = t;
}
long t0 = System.nanoTime();
System.load(p.toAbsolutePath().toString());
System.out.printf("%s %.1f ms%n", a.length > 1 ? "fresh" : "stable", (System.nanoTime() - t0) / 1e6);
}
}
printf 'int tiny_fn(void){return 42;}\n' > tiny.c && clang -dynamiclib -o libtiny.dylib tiny.c
javac T.java
java T libtiny.dylib fresh # fresh 1335.6 ms
java T libtiny.dylib # stable 0.5 ms
Would you consider extracting the library once, under a name derived from its contents (for example a hash of the resource), into a stable directory, and reusing it when it is already there? Writing it to a temp file and renaming it into place would keep concurrent JVMs safe, and the file would not be deleted after loading. If the stable copy is already loaded by another class loader in the same JVM, falling back to a fresh copy as today would keep that case working. This would also help with #933, since the temp directory would no longer fill up with copies.
The current workaround is to set org.conscrypt.native.workdir to an unwritable directory and put an extracted copy of the library on java.library.path, which relies on Conscrypt's fallback order. Seen with conscrypt-openjdk-uber 2.9.0, JDK 21, macOS 26 on Apple Silicon.
- Lingua principale
- Java
- Stelle
- 1.4k
- Fork
- 332
- Merge medio
- 2g 56m
- PR unite (30g)
- 5
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/conscrypt
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 3/5 Mezza giornata Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
Tutte le issue di google/conscrypt
Issue simili
-
beginner difficulty: easy documentation good first issue hacktoberfest help wanted observability size/S up-for-grabs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
dmitriy-iliyov/spring-transactional-outbox#82 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
RamazanKara/nightjar#264 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
netty/netty#18628 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 87/100
apache/flink-agents#1500 ·
I maintainer di solito rispondono entro 1 giorno
-
bug frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
sylvainmetayer/planning-equipes#495 ·
I maintainer di solito rispondono entro 1 giorno