Optimizing BoofCV

From BoofCV
Jump to navigationJump to search

This page discusses how you can optimize BoofCV for your specific application. This includes tips on speed, reducing the size of a jar, and avoiding common mistakes.

Speed: Warming Up Java

One common mistake that people make when dealing with Java in general is not allowing it time to warm up. Basically all modern virtual machine language (like Java) optimize at runtime to make things run faster. Often people who are used to C++ expect the code to be highly optimized and provide a constant runtime. In most real world applications this is a non issue as you aren't constantly starting and stopping the JVM. So if you want to get the most performance keep the JVM running and ignore the first few times it processes an image as it will be 2x or 3x slower.

Speed: Native Code

While it is possible to speed up BoofCV by replacing parts of it with native code, it's often not worth it and certainly not the lowest hanging fruit. Typically, low level operations, such as image convolution, benefit the most and if you write hand optimized SIMD code you can probably beat what's in BoofCV by 2x. For higher level operations which aren't SIMD friendly there is unlikely to any improvement in fact the code could very well be slower until you spend a lot of time learning how to optimize the data structures or deal with cache issues effectively.

Internally, some operations in BoofCV allow you to plug in 3rd party alternatives. The best place to learn how to do that is with BoofCPP. That was an attempt to plug in C++ code and get things to run faster. Primary reason it hasn't been updated is that the real world performance boost was about ~10% and not worth the additional development effort.


Jar Size

Occasionally comments are made about BoofCV requiring a lot amount of disk space for simple tasks. For the developers of BoofCV that's a bit of a surprise since it's core components have very few external dependencies.

  1. Don't use 'boofcv-all'!
  2. Did you only include 'boofcv-core'?
  3. Did you only include individual modules that 'boofcv-core' reference?
  4. Did you exclude DeepBoof? See example below
  5. Have you used a tool that removes unused code? See Stack Overflow

Excluding DeepBoof

api("org.boofcv:boofcv-core:$VERSION") {
	exclude group: 'org.deepboof'