25 ms·
I'm building a Java HFT engine and the amount of things AI gets wrong is eye opening. If I didn't benchmark everything I'd end up with much less optimized solut
by matt_heimer 6mo ago
I'm building a Java HFT engine and the amount of things AI gets wrong is eye opening. If I didn't benchmark everything I'd end up with much less optimized solution.
Examples: AI really wants to use Project Panama (FFM) and while that can be significantly faster than traditional OO approaches it is almost never the best. And I'm not taking about using deprecated Unsafe calls, I'm talking about using primative arrays being better for Vector/SIMD operations on large sets of data. NIO being better than FFM + mmap for file reading.
You can use AI to build something that is sometimes better than what someone without domain specific knowledge would develop but the gap between that and the industry expected solution is much more than 100 hours.
- mtrovo 6mo agoI think the main issue is treating LLM as a unrestrained black box, there's a reason nobody outside tech trust so blindly on LLMs. The only way to make LLMs useful for now is to restrain their hallucinations as much as possible with evals, and these evals need to be very clear about what are the goal you're optimizing for. See karpathy's work on the autoresearch agent and how it carry experiments, it might be useful for what you're doing.
- riffraff 6mo ago> there's a reason nobody outside tech trust so blindly on LLMs. Man, I wish this was true. I know a bunch of non tech people who just trusts random shit that chatgpt made up. I had an architect tell me "ask chatgpt" when I asked her the difference between two industrial standard measures :) We had politicians share LLM crap, researchers doing papers with hallucinated citations.. It's not just tech people.
- deleted 6mo ago[deleted]
- withinboredom 6mo agoWe were working on translations for Arabic and in the spec it said to use "Arabic numerals" for numbers. Our PM said that "according to ChatGPT that means we need to use Arabic script numbers, not Arabic numerals". It took a lot of back-and-forths with her to convince her that the numbers she uses every day are "Arabic numerals". Even the author of the spec could barely convince her -- it took a meeting with the Arabic translators (several different ones) to finally do it. Think about that for a minute. People won't believe subject matter experts over an LLM. We're cooked.
- dvfjsdhgfv 6mo agoMan this is maddening.
- tstenner 6mo agoThe architect should have required Hindu numbers. Same result, but even more confusion.
- ThrowawayR2 6mo agoKind of a tangent but that did make me curious about how numbers are written in Arabic: https://en.wikipedia.org/wiki/Eastern_Arabic_numerals https://en.wikipedia.org/wiki/Eastern_Arabic_numerals
- tracker1 6mo agoI guess "Western Arabic" would have been more precise.
- godelski 6mo agoHonestly I think we're just becoming more aware of this way of thinking. It's certainly exacerbated it now that everyone has "an expert" in their pocket. It's no different than conspiracy theorists. We saw a lot more with the rise in access to the internet. Not because they didn't put in work to find answers to their questions, but because they don't know how to properly evaluate things and because they think that if they're wrong then it's a (very) bad thing. But the same thing happens with tons of topics, and it's way more socially acceptable. Look how everyone has strong opinions on topics like climate, rockets, nuclear, immigration, and all that. The problem isn't having opinions or thoughts, but the strength of them compared to the level of expertise. How many people think they're experts after a few YouTube videos or just reading the intro to the wiki page? Your PM is no different. The only difference is the things they believed in, not the way they formed beliefs. But they still had strong feelings about something they didn't know much about. It became "their expert" vs "your expert" rather than "oh, thanks for letting me know". And that's the underlying problem. It's terrifying to see how common it is. But I think it also leads to a (partial) solution. At least a first step. But then again, domain experts typically have strong self doubt. It's a feature, not a bug, but I'm not sure how many people are willing to be comfortable with being uncomfortable
- roncesvalles 6mo agoAnd the worst part is, these people don't even use the flagship thinking models, they use the default fast ones.
- j45 6mo agoThere’s a possibility the same people might believe anything they read on social media or via Google and it’s something worthy of attention.
- closewith 6mo agoIn my experience, people outside of tech have nearly limitless faith in AI, to the point that when it clashes with traditional sources of truth, people start to question them rather than the LLM.
- FpUser 6mo agoI am curious about what causes some to choose Java for HFT. From what I remember the amount of virgin sacrifices and dances with the wolves one must do to approach native speed in this particular area is just way too much of development time overhead.
- nly 6mo ago"HFT" means different things to different people. I've worked at places where ~5us was considered the fast path and tails were acceptable. In my current role it's less than a microsecond packet in, packet out (excluding time to cross the bus to the NIC). But arguably it's not true HFT today unless you're using FPGA or ASIC somewhere in your stack.
- atomicnumber3 6mo agoThe one person who understands HFT yeah. "True" HFT is FPGA now and also those trades are basically dead because nobody has such stupid order execution anymore, either via getting better themselves or by using former HFTs (Virtu) new order execution services. So yeah there's really no HFT anymore, it's just order execution, and some algo trades want more or less latency which merits varying levels of technical squeezing latency out of systems.
- matt_heimer 6mo agoSoftware HFT? I see people call Python code HFT sometimes so I understand what you mean. It's more in-line with low latency trading than today's true HFT. I don't work for a firm so don't get to play with FPGAs. I'm also not co-located in an exchange and using microwave towers for networking. I might never even have access to kernel networking bypass hardware (still hopeful about this one). Hardware optimization in my case will likely top out at CPU isolation for the hot path thread and a hosting provider in close proximity to the exchanges. The real goal is a combination of eliminating as much slippage as possible, making some lower timeframe strategies possible and also having best class back testing performance for parameter grid searching and strategy discovery. I expect to sit between industry leading firms and typical retail systematic traders.
- deleted 6mo ago
- grim_io 6mo agoWouldn't Java always lose in terms of latency against a similarly optimized native code in, let's say, C(++)?
- tyingq 6mo agoDepends. Many reasons, but one is that Java has a much richer set of 3rd party libraries to do things versus rolling your own. And often (not always) third party libraries that have been extensively optimized, real world proven, etc. Then things like the jit, by default, doing run time profiling and adaptation.
- andriy_koval 6mo agoJava has huge ecosystem in enterprise dev, but very unlikely it has ecosystem edge in high performance/real time compute.
- deleted 6mo ago[deleted]
- jacquesm 6mo agoNot necessarily. Java can be insanely performant, far more than I ever gave it credit for in the first decade of its existence. There has been a ton of optimization and you can now saturate your links even if you do fairly heavy processing. I'm still not a fan of the language but performance issues seem to be 'mostly solved'.
- nly 6mo ago"Saturating your links" is rarely the goal in HFT. You want low deterministic latency with sharp tails. If all you care about is throughput then deep pipelines + lots of threads will get you there at the cost of latency.
- jodleif 6mo agoAs long as you tune the JVM right it can be faster. But its a big if with the tune, and you need to write performant code
- jacquesm 6mo agoAI is extremely good at the things that it has many examples for. If what you are doing is novel then it is much less of a help, and it is far more likely to start hallucinating because 'I don't know' is not in the vocabulary of any AI.
- Filligree 6mo ago> because 'I don't know' is not in the vocabulary of any AI. That is clearly false. I’m only familiar with Opus, but it quite regularly tells me that, and/or decides it needs to do research before answering. If I instruct it to answer regardless, it generally turns out that it indeed didn’t know.
- jacquesm 6mo agoI haven't had that at all, not even a single time. What I have had is endless round trips with me saying 'no, that can't work' and the bot then turning around and explaining to me why it is obvious that it can't work... that's quite annoying.
- dwaltrip 6mo agoTry something like: > Please carefully review (whatever it is) and list out the parts that have the most risk and uncertainty. Also, for each major claim or assumption can you list a few questions that come to mind? Rank those questions and ambiguities as: minor, moderate, or critical. > Afterwards, review the (plan / design / document / implementation) again thoroughly under this new light and present your analysis as well as your confidence about each aspect. There's a million variations on patterns like this. It can work surprisingly well. You can also inject 1-2 key insights to guide the process. E.g. "I don't think X is completely correct because of A and B. We need to look into that and also see how it affects the rest of (whatever you are working on)."
- jacquesm 6mo agoOk! I will try that, thank you very much.
- LtWorf 6mo agoI've seen SQL injection and leaked API tokens to all visitors of a website :)
- smokel 6mo ago> AI really wants to use Project Panama It would help if you briefly specified the AI you are using here. There are wildly different results between using, say, an 8B open-weights LLM and Claude Opus 4.6.
- matt_heimer 6mo agoI've been using several. LM Studio and any of the open weight models that can fit my GPU's RAM (24GB) are not great in this area. The Claude models are slightly better but not worth they extra cost most of the time since I typically have to spend almost the same amount of time reworking and re-prompting, plus it's very easy to exhaust credits/tokens. I mostly bounce back and forth between the codex and Gemini models right now and this includes using pro models with high reasoning.
- colechristensen 6mo agoThen you list all of the things you want it not to do and construct a prompt to audit the codebase for the presence of those things. LLMs are much better at reviewing code than writing it so getting what you want requires focusing more on feedback than creation instructions.
- mewpmewp2 6mo agoI would say that if AI has to make decisions about picking between framework or constructs irrelevant to the domain at hand, it feels to me like you are not using the AI correctly.
- tracker1 6mo agoMaybe a silly question, but why Java? As a C# guy, my experience with AI is it hasn't been great with it, and I'd suspect similar for Java. I'd probably go with Rust, which my own efforts with AI has done really well with, even if I'm far from a Rust expert.