7 ms·
JavaCPP
- jesuslop 11y agoBookmarked, looks useful and leaner than swig and any other thing I know of.
- amelius 11y agoSomewhat off-topic. I recently got interested in Java and its ecosystem because of Clojure. However, what bugs me is the startup time for Java. Since this is mature technology, I cannot believe it takes so long for an executable to start. One guess is that this is because of the garbage collector inside the VM, but that doesn't make much sense because NodeJS also uses a garbage collector and it starts instantly (and it even has to parse & compile the code upon startup, which the Java VM doesn't even have to do). So... I'm puzzled. Any comments? This is not meant as a trolling question.
- htcw 11y agoBriefly, the JVM starts very quickly. Most of the time is spent loading the clojure.core namespace. See http://blog.ndk.io/jvm-slow-startup.html http://blog.ndk.io/jvm-slow-startup.html
- loevborg 11y agoYes, unfortunately Clojure startup performance problems are home-grown and cannot be blamed on the JVM. On the other hand, once a Clojure repl is running, you can keep adding things without recompiling or even losing state, which can be a huge performance advantage, assuming that OP's troubles are related to dev xp.
- amelius 11y agoWell talking about dev xp, I like to follow the Unix tradition, where one can make many tools, and run them from the commandline, combine them in scripts, etc. But obviously this only works if startup is on the order of milliseconds, not seconds. NodeJS lets us do this, so I was wondering why not Clojure/Java. Anyway, I'm still curious how much faster running an AOT compiler on Clojure would be.
- djhworld 11y agoMost 'script' like tools written in Java will start very quickly. Clojure isn't really designed for this use case.
- oh_sigh 11y agoYou could use a long-running JVM for these tools if there's a compelling use-case? Not ideal but if it lets you write tools in the language of your choice it may be worth it.
- chrisseaton 11y agoIt doesn't make any sense to blame the garbage collector. During startup you're loading classes, allocating structures, and verifying byte code. There aren't things that involve garbage collection (allocating with a tracing GC is generally by bump-pointer so is very efficient). I work on a large Java project (JRuby) and for us the largest component of time spent is on loading classes. Also, startup code is likely to run in the interpreter rather than being JIT compiled, which is also slower. The solution we're looking at is ahead of time compilation. This avoids class loading and interpretation, and it does seem to solve the problem (we're back to ms startup time). In V8 (Node.js) the majority of the core language and library features are effectively already AOT compiled as they're implemented in C++. In the OpenJDK (and most JVMs) a lot of this is implemented in Java, so that has to be loaded and interpreted rather than executed natively.
- amelius 11y agoBy AOT, do you mean something like this: http://www.excelsiorjet.com/ http://www.excelsiorjet.com/ If you look at the "Benefits" tab, you will see that startup will still take on the order of 1+ seconds, which is quite long IMO. Also, would this work with Clojure? And are there open-source AOT compilers which work with Clojure?
- the8472 11y agoAfaik IBM's JVM supports class data sharing, which effectively provides AOT behavior once they have been JITed. For oracle's VM they're working on a commercial feature https://www.youtube.com/watch?v=Xybzyv8qbOc https://www.youtube.com/watch?v=Xybzyv8qbOc There also are things like nailgun which simply prestart a JVM and then delegate to the loaded JVM when you invoke some command. It may be a bit of a workaround, but if your use-case is to frequently start extremely shortlived programs that might be worth it.
- Alphasite_ 11y agoDoesn't Dalvik use a machinist similar to railgun to achieve its performance?
- meddlepal 11y agoI haven't tried using it recently, but consider passing the -client flag rather than the -server flag at JVM boot and see if it's any better? The -server flag is great for production because it does a ton more pre-optimization at bootup.
- RhodesianHunter 11y agoThis appears to be more an artifact of Clojure than Java.
- Gibbon1 11y agoI wonder a bit if Clojure isn't atypical though? I mean my compiler starts up fast too, then takes a fairly long time to grind away. However this gets done once.
- Hupriene 11y agoAlex Miller is collecting information on impact of clojure's slow startup time. For that and some good discussion of the causes of clojure's slow startup time see: https://groups.google.com/forum/#!msg/clojure/MG8UTcgFhYc/lBiQBoCjAwAJ https://groups.google.com/forum/#!msg/clojure/MG8UTcgFhYc/lB...
- sorokod 11y agoMaybe to do with garbage collection. JVM uses generational collectors that depend on the weak generational hypothesis. This hypothesis doesn't hold during start-up as many long lived objects are created in a short period of time.
- deleted 11y ago[deleted]
- pjmlp 11y ago> However, what bugs me is the startup time for Java. Which is just a few ms for pure Java. If you mean it in association with Clojure, blame Clojure initialization code, not Java itself.
- zwetan 11y agoquite an interesting subject: startup time :) sure the garbage collector make a difference but the big difference imho is how the VM interpret the bytecode. In the JVM, the long startup time is because the bytecode is fully loaded, verified, etc. then interpreted If you compare with other VM, like the AVM2 (ActionScript Virtual Machine 2), there the bytecode is considered as a stream, even if your program is many hundred of MB, the interpreter kick in much earlier. It is explained in a presentation at Standord University by Rick Reitmaier from Adobe Systems see at 31:35, https://youtu.be/BjYRzwDEIyw?t=1894 https://youtu.be/BjYRzwDEIyw?t=1894 , he talk about startup time. In my own experience working with AVM2 on my OSS project Redtamarin https://github.com/Corsaair/redtamarin https://github.com/Corsaair/redtamarin , this startup time was key. Wether you run the AVM2 from a shell script, a standalone executable or even as CGI under Apache, the avmshell which run, load, verify, interpret the bytecode, startup in matter of milliseconds. But it is a trade, you could say JVM: slow startup time, faster execution AVM2: fast startup time, slower execution
- gkya 11y agoThe thing that put me off from Clojure was the amount of memory it used. It's ok by default, but when I wanted to use emacs+cider, it consumes about a gigabyte of the ram. Having to work on a 2GB machine, it becomes painful to use.
- bcg1 11y agoYou may want to check if you're using the server JVM vs. the client JVM also... one of the differences is the level of optimization that the VM tries to do. The server JVM does deeper analysis during classloading, which increases startup to,e. If you have very short running processes (which I'm assuming you do if you're concerned with startup time) the client JVM may be more appropriate. Also in general, the vanilla JVM startup is pretty quick... the slowness you're experiencing is probably "userspace" code.
- agumonkey 11y agoIt's a bit like debian vs arch. Apt is slower, because the packaging system does more. Maybe you only need pacman 'semantics' though.
- agibsonccc 11y agoJavaCPP user here. Amazing framework. The ideas behind it are really cool (auto generate JNI headers with annotations). Ensure you checkout the presets: https://github.com/bytedeco/javacpp-presets https://github.com/bytedeco/javacpp-presets Another awesome thing built with it: https://github.com/WPIRoboticsProjects/GRIP https://github.com/WPIRoboticsProjects/GRIP
- jevinskie 11y agoI took a look at the LLVM preset and it looked like you had to pass object handles to static functions. I'd prefer to have an actual, say, LLVM::Module equivalent object in Java that you can call member functions on. Are all the presets like this?
- agibsonccc 11y agoI would bring it up with the project maintainer. He's based in Japan(time zone) but I flagged this thread for him for when Japan is awake.
- bytedeco 11y agoNo, that's because in the specific case of LLVM only the C API is currently mapped. We'd have to work a little bit harder for the C++ API, but there is interest in doing so, if only to use it as a better parser for JavaCPP itself: Improve Parser: Use the Clang API https://github.com/bytedeco/javacpp/issues/51 https://github.com/bytedeco/javacpp/issues/51
- needusername 11y agoAre you seeing reference processing showing up in you GC logs due to it's reliance on PhantomReferences?
- deleted 11y ago[deleted]
- ww520 11y agoLooks very useful. It would help to bridge to many C++ packages. I wonder what the deployment option is. Can it bundle multiple platform libraries (e.g. Windows and Linux X86) in one package?
- agibsonccc 11y agoYes. You can have a custom shell script that sets up the deployment. It's not ideal but it works in practice: http://search.maven.org/#search%7Cga%7C1%7Cjavacpp http://search.maven.org/#search%7Cga%7C1%7Cjavacpp
- millionaire22 11y agopretty cool
- corysama 11y agoAny recommendations for going the other way? I'm interested in writing Android applications entirely in C++, but obviously a lot of interaction with Java is required. It would be great if there was a way to use JNI well enough to never be tempted to write little bits of Java here and there.
- bytedeco 11y agoI recommend Jace for that: https://bitbucket.org/cowwoc/jace/wiki/Home https://bitbucket.org/cowwoc/jace/wiki/Home
- andrewguenther 11y agoFor those of you looking at something like this, remember that JNI (no matter how you wrap it) is still incredibly slow when trying to pass larger data structures (>1KB).
- bytedeco 11y agoOn modern JVM we can use direct NIO buffers and let Java access native memory directly at full speed. There is (almost) no overhead at all anymore, so if we do it that way, it's pretty fast actually.
- agibsonccc 11y agoFwiw: we do this in our blas implementation. https://github.com/deeplearning4j/libnd4j https://github.com/deeplearning4j/libnd4j
- deleted 11y ago[deleted]