TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

NativeJIT – JIT compilation of expressions involving C data structures

130 pointsby AnbeSivamover 8 years ago

11 comments

stormbrewover 8 years ago
Title seems incorrect, or at least misleading. It is not a JIT for C++ code (ie. not &quot;C++ to...&quot;), it is a JIT library for C++ that seems focused on compiling arithmetic algorithms as used in bing.<p>Interestingly, it requires the functions called by the JIT&#x27;d code to be side-effect free, since it guarantees it will call any given function invocation <i>at least once</i>, since it evaluates both sides of any but top level branches. See &quot;Design Notes and Warnings&quot; in <a href="https:&#x2F;&#x2F;github.com&#x2F;BitFunnel&#x2F;NativeJIT&#x2F;blob&#x2F;master&#x2F;Documentation&#x2F;README.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;BitFunnel&#x2F;NativeJIT&#x2F;blob&#x2F;master&#x2F;Documenta...</a>
评论 #12431055 未加载
评论 #12428647 未加载
paulasmuthover 8 years ago
What I find amazing about NativeJIT is how small the codebase seems to be -- under 10k SLOC. Impressive!<p>Will seriously consider using this to speed up expression execution in EventQL [0] (we shied away from llvm so far because it&#x27;s such a massive dependency).<p>[0] <a href="https:&#x2F;&#x2F;eventql.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;eventql.io&#x2F;</a>
bedatadrivenover 8 years ago
This is similar to a technique used in Renjin to compile specific vector computation expressions down to straight-line JVM bytecode, which is then JITed down to machine code. It&#x27;s a very powerful technique because it removes all the indirection involved in a evaluating dynamic expressions and lets the processor just do its job.<p>For example, if you evaluate sum(sqrt(x^2 + y^2) * 3) in Renjin, and x or y happen to be very long vectors, then we&#x27;ll jit out a JVM class for this specific expression that would look something like this in Java:<p><pre><code> class JittedComputation1E5374A3 { SEXP compute(SEXP[] args) { double[] x = args[0].toDoubleArrayUnsafe(); double[] y = args[1].toDoubleArrayUnsafe(); double sum = 0; for(int i=0;i&lt;x.length;++i) { double xi = x[i]; double yi = y[i] sum += Math.sqrt(xi*xi+yi*yi) * 3; } return DoubleVector.valueOf(sum); } } </code></pre> The computation is specialized to the types of x and y, so if for example x is a sequence 1:1000000 then a new class gets written for that doesn&#x27;t even use an array for x.<p>The speedup is so impressive that even if you don&#x27;t cache the compiled expression you see dramatic improvements: <a href="http:&#x2F;&#x2F;www.renjin.org&#x2F;blog&#x2F;2015-06-28-renjin-at-rsummit-2015.html" rel="nofollow">http:&#x2F;&#x2F;www.renjin.org&#x2F;blog&#x2F;2015-06-28-renjin-at-rsummit-2015...</a>
AnbeSivamover 8 years ago
Related -<p><a href="http:&#x2F;&#x2F;bitfunnel.org&#x2F;debugging-nativejit&#x2F;" rel="nofollow">http:&#x2F;&#x2F;bitfunnel.org&#x2F;debugging-nativejit&#x2F;</a><p><a href="https:&#x2F;&#x2F;twitter.com&#x2F;danluu&#x2F;status&#x2F;771622870132809729" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;danluu&#x2F;status&#x2F;771622870132809729</a>
denoover 8 years ago
Better link: <a href="http:&#x2F;&#x2F;bitfunnel.org&#x2F;getting-started-with-nativejit&#x2F;" rel="nofollow">http:&#x2F;&#x2F;bitfunnel.org&#x2F;getting-started-with-nativejit&#x2F;</a>
willvarfarover 8 years ago
I know it can be sandboxed, but it makes the hair on the back of my neck stand up to think that something people type into a search box on a web page gets turned into machine code and executed.. :)
评论 #12431030 未加载
评论 #12428890 未加载
eDameXxXover 8 years ago
More information: <a href="http:&#x2F;&#x2F;bitfunnel.org" rel="nofollow">http:&#x2F;&#x2F;bitfunnel.org</a>
samfisher83over 8 years ago
Can&#x27;t you use function overloading? or function pointers? Why do you need to recompile the code? Can someone give an example of where this should be used?
评论 #12431677 未加载
SCHiMover 8 years ago
Looks very similar to <a href="https:&#x2F;&#x2F;github.com&#x2F;asmjit&#x2F;asmjit" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;asmjit&#x2F;asmjit</a>
zokierover 8 years ago
So would it make sense to use this as the engine for something akin to jq or xsv?
EgoIncarnateover 8 years ago
The title is wrong. This is not a C++ to x86 JIT (which would be really cool), this is a JIT library for C++ (of which there are a number). It has it&#x27;s own domain specific language for expressions. It doesn&#x27;t take arbitrary C++. No std C++ syntax, no classes, etc.<p>Ex:<p><pre><code> &#x2F;&#x2F; nativeJIT DSL auto &amp; area = expression.Mul(rsquared, expression.Immediate(PI)); auto function = expression.Compile(area); &#x2F;&#x2F; C++ auto area = rsquared * PI;</code></pre>
评论 #12429395 未加载
评论 #12431062 未加载