NativeJIT is an open-source cross-platform library for high-performance just-in-time compilation of expressions involving C data structures. The compiler is light weight and fast and it takes no dependencies beyond the standard C++ runtime. It runs on Linux, OSX, and Windows. The generated code is optimized with particular attention paid to register allocation.
The compiler was developed by the Bing team for use in the Bing search engine. One important use is scoring documents containing keywords that match a user's query. The scoring process attempts to gauge how well each document matches the user's intent, and as such, depends on the specifics of how each query was phrased. Bing formulates a custom expression for each query and then uses NativeJIT to compile the expression into x64 code that will be run on a large set of candidate documents spread across a cluster of machines.
We knew from the get go that throughput and latency would be essential when processing queries at scale, so we put a lot of effort in to making NativeJIT run fast.
Our design point was scenarios where
- The expression isn't known until runtime.
- The expression will be evaluated enough times to amortize the cost of compilation.
- Latency and throughput demands require low cost for compilation.
Here's trivial "Hello, world" level example that computes the area of a circle:
Here is the generated assembly code on Windows:
This example shows an expression that multiplies a number by itself. We also support a wide variety of arithmetic and logical operations, pointer and array operations, conditionals, accessing structure fields, and calling out to C functions. See our preliminary API docs for more information and the Examples/ directory for more examples.
In order to build NativeJIT you will need CMake (2.8.11+), and a modern C++ compiler (gcc 5+, clang 3.4+, or VC 2015+). You can run CMake directly to generate the appropriate build setup for your platform. Alternately, we have some scripts that have the defaults that we use available.
For *nix platforms (including OS X),
If you're on Ubuntu 15+, you can install dependencies with:
On Ubuntu 14 and below, you'll need to install a newer version of CMake. To install a new-enough CMake, see this link. If you're using gcc, you'll also need to make sure you have gcc-5 (sudo apt-get install g++-5).
To override the default compiler, set the CXX and CC environment variables. For example, if you have clang-3.8 installed as clang-3.8 and are using bash:
Install XCode and then run the following command to install required packages using Homebrew (http://brew.sh/):
NativeJIT can be built on OS X using either standard *nix makefiles or XCode. In order to generate and build makefiles, in the root NativeJIT directory run:
If you want to create an Xcode project instead of using Makefiles, run:
Install the following tools:
- Visual Studio 2015 with C++ compiler
- CMake (http://www.cmake.org/download/)
You can get the free version of Visual Studio here. Note that if you're installing Visual Studio for the first time and select the default install options, you won't get a C++ compiler. To force the install of the C++ compiler, you need to either create a new C++ project or open an existing C++ project.
In order to configure solution for Visual Studio 2015 run the following commands from the root NativeJIT directory:
From now on you can use the generated solution build-msvc\NativeJIT.sln from Visual Studio or build from command line using cmake.