-
-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hello,
i'm trying to use swc4j but the startup is quite slow on my Mac (M2 Air),
it takes more than 5 seconds to just run
var swc4j = new Swc4j();
If i try to load the native library using the following code, it's still slow but around 400 ms
String libName = "libswc4j-macos-arm64.v.1.3.0.dylib";
URL url = Class.forName("com.caoccao.javet.swc4j.Swc4jNative").getResource("/" + libName);
Path tmpDir = Files.createTempDirectory("swc4j-native");
tmpDir.toFile().deleteOnExit();
Path nativeLibTmpFile = tmpDir.resolve(libName);
nativeLibTmpFile.toFile().deleteOnExit();
try (InputStream in = url.openStream()) {
Files.copy(in, nativeLibTmpFile);
}
System.load(nativeLibTmpFile.toAbsolutePath().toString());
Compared to your code, this code
- uses createTempDirectory() which is a fresh directory so no purge needed,
- path.toFile().deleteOnExit() so deletion is not an issue
- uses Files.copy() for fast copy
For me, this code is Java 8 compatible and faster.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request