Hacker News new | ask | show | jobs
by motoboi 25 days ago
Rust? OK.

C++ or go? Then you'll have to take a very closer look, because the java JIT is wonderful. A masterpiece of several hands, actually.

1 comments

If low latency is your goal than you don't want JIT. JIT has two issues in low latency, first the first time through your code isn't compiled yet and so you get high latency. Second, it optimizes for the common case, which means when you hit an exception that exception will be higher latency because everything hits a branch miss.

Of course we are talking generals here. Sometimes the above is acceptable and Java/JIT is just fine. Sometimes it is unacceptable and you cannot use Java/JIT. Know your domain.

Of course in all cases (C, Rust, C++), you have to understand the system and what it is doing. Every language has a standard library that will do things that are not low latency on you. You have to know which library functions will do what, memory allocation and copies are both things that code often does without thought that are incompatible with low latency. No matter what you need to know what your language does that is against you.

> If low latency is your goal than you don't want JIT. JIT has two issues in low latency...

There's startup "AOT cache" via Leyden that speeds up startup. Isn't native speed up it's quite a big boost.

Then there's GraalVM that does give you a native image. Real AOT.

Valid points, but this doesn't mean JIT doesn't work for relatively lower-latency coding.

To avoid the compilation etc. hit, common practice is to do some "warmups" before serving users. (Another reply has other ways to avoid this hit.)

Handling exceptions is higher latency, but they can/should be optimized out, so you're not hitting exceptions as part of your standard workflow (or even your 1% workflow).

Exceptions depend on the workflow. For some high frequently trades the normal case is you won't make money so don't trade - the exceptions for them are the only case where latency matters.

Don't read the above, as you can't use JIT or Java for low latency. I never intended to say that. However, you are going to be fighting the system if you do try to use them. fighting the system even more than C where you have more control

> If low latency is your goal than you don't want JIT.

To be more specific, you don't want Java-style-JIT. Julia JIT (which functions closer to AOT in this case) is fine for low latency.