12 ms·
Jane Street and the OCaml Compiler (2018) [video]
- smabie 7y agoi asked this question at my Jane Street interview, but never got a real answer: how does a market making latency arb firm handle GC pauses that are inherent with any GC language? OCaml is better in this regard than, say, the JVM, but it still seems problematic. I know they wrote some FPGA compiler stuff with OCaml, but I can't imagine that all of their execution is running through FPGAs. Even if it's possible, it seems like an uphill battle; something like Rust would probably be easier to deal with (at least for their realtime code).
- QuinnWilton 7y agoI don't know what Jane Street does, and can't speak for them. That being said, I've heard of some firms using the JVM that just tune things such that the garbage collector will never trigger, and then they restart the VM every night. Unfortunately I don't have a citation for that. I think I've seen it talked about before here on HN before.
- Reelin 7y agoI'm not entirely clear on the use case, but Disruptor by LMAX Exchange is for the JVM and seems very concerned with latency. (https://github.com/LMAX-Exchange/disruptor/wiki/Performance-Results https://github.com/LMAX-Exchange/disruptor/wiki/Performance-...)
- imglorp 7y agoHere's the backstory, worth a good read in general. https://martinfowler.com/articles/lmax.html https://martinfowler.com/articles/lmax.html I suspect at least one use case has gone away since the Fowler wrote that: wanting to saturate the write channel into a database in general. Consistent hashing document DBs like DynamoDB, Cassandra, etc. are basically infinitely scalable for writes. It's not clear to me if LMAX still makes sense if you want to assemble the db writes into a strongly ordered stream.
- nimchimpsky 7y ago"wanting to saturate the write channel into a database in general. Consistent hashing document DBs like DynamoDB, Cassandra, etc. are basically infinitely scalable for writes." I don't really understand what are you are saying there ? But we use disruptors for processing millions of messages/events as quickly as possible, with a variety of different consumers.
- andrewnc 7y agoThis is a really fascinating question. When I chatted with some of the Jane Street crew at NeurIPS they were adamant in the benefits of OCaml's Hindley-Milner type system. I didn't ask, but am curious, how that compares to the type guarantees of Rust? Would moving to Rust cause them to lose that advantage of compile time error catching? I've never written a line of Rust (hopefully that changes soon) so I don't know, but am certainly interested.
- smabie 7y agoOcaml doesn't have a HM type system. I mean I guess it does, but Ocaml supports a lot of stuff HM doesn't.
- mijoharas 7y agoTechnically the same is true of Haskell[0] but most people (myself included) will refer to the kind of type system used as Hindley-Milner for simplicities sake. (Both are more powerful though) [0] https://cstheory.stackexchange.com/a/30528/20014 https://cstheory.stackexchange.com/a/30528/20014
- throwaway720348 7y agoRust type's system has a similar power level to OCaml's but without modules (which are used heavily at JS) and with linear types/lifetimes. Rust would probably be a good fit for JS, but of course it takes a lot to overcome the momentum of 20 years of using primarily one language.
- helsinki 7y agoThings to consider: The company is >20 years old. OCaml is a general purpose language that provides an equilibrium between the avoidance of bugs introduced by state (like all functional languages), speed, and polymorphic type inference. At the time of adoption, the other choices were Haskell (too academic, not practical), Erlang (no type inference, not suited for large code bases with complex business logic), and lisp (too slow, loose/optional type system). The last time I checked, OCaml was third only to C and C++ in terms of speed. It is also important to consider how intellectually stimulating it is to write OCaml. If you can achieve the three things mentioned at the top of this paragraph while also creating a brand of gravitas and intellect that attracts top-tier talent, of course you would choose OCaml. Would a new, uninitiated market maker write something in OCaml? Unlikely, as they would probably use C++, Rust, or Scala with a 1TB heap and GC disabled. Ignoring the learning curve and time/dollar constraints of starting a hedge fund, I would choose OCaml over the three mentioned. [1]https://en.m.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system https://en.m.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_... [2]https://courses.cs.washington.edu/courses/cse341/04wi/lectures/06-ml-polymorphic-types.html https://courses.cs.washington.edu/courses/cse341/04wi/lectur...
- tartoran 7y agoWhy C++ now but not then, 20+ years ago? And would F# be suitable for the task? Im genuinely interested
- helsinki 7y agoPresumably Jane Street didn’t choose C++ because they wanted to reduce bugs introduced by the preservation of state; the killer of prop shops. F# was developed six years after their founding, hence too young, and more importantly, a Microsoft-owned clone of OCaml. I don’t think it even ran on Linux before 2015. Today, F# might just suit the job, assuming you are open to being locked into the .NET family. An interesting idea to say the least. Why C++ now? Still the fastest and tons of quants and highly skilled programmers know it. When you consider the correlation between C++ developers’ technical acumen and quantitative skills, coupled with the maturity and increasing convenience of the ecosystem, it makes sense.
- matlin 7y agoIn Elixir/Erlang there is no global pausing for garbage collection, instead each process is individual garbage collected. And I remember hearing about a strategy that allows you to avoid it entirely by ensuring your process's lifetime is short enough (or heap size big enough) that it basically never happens despite the BEAM (Erlang VM) running with garbage collection. Edit: my point is that it is likely avoidable through certain coding practices in garbage collected environments.
- dnautics 7y agoThis is only possible due to the way that the BEAM VM and its languages are architected; the gc itself is "not the smartest", but it doesn't have to be because there is no shared memory and process boundaries are failure domains.
- hendzen 7y agoFrom what I've heard Jane Street's bread and butter isn't latency sensitive market making on public equities, but creation/redemption arbitrage on ETFs, especially ones that hold a lot of relatively illiquid stuff like various fixed income ETFs. Creating and redeeming those ETFs might involve pricing an emerging market sovereign or corporate bond that might have only traded a few times in the last year. So their expertise is more around smartly trading really weird stuff as opposed to the pure speed players like Jump, Citadel or Virtu Financial. That said JS is probably in a lot of different products, some more latency sensitive than others, but speed isn't what they are known for.
- wk_end 7y agoAnywhere that's latency sensitive they write code carefully so that it doesn't trigger the GC.
- whb07 7y agoThey are market makers not those battling the swings at the micro second scale. Yaron Minsky replied this in some random video I saw a random night, though I cannot recall which. So their edge isn’t based on speed. They gain more from correctness and ability to express these ideas.
- smabie 7y agoMarket makers are incredibly exposed to ms scale swings since they're warehousing a lot more risk than a HFT firm.
- tbr1 7y agoYou can write zero-alloc OCaml code, since the standard compiler is very predictable in when it will allocate closures, etc. The Flambda compiler makes things even nicer in removing allocations for some common idioms. [1]: https://twitter.com/yminsky/status/947064713237684224 https://twitter.com/yminsky/status/947064713237684224
- easytiger 7y agoDid they say that latency isn't a big factor in their PnL, but they let their tech guys waste their time over it to keep a big happy family?
- AllanHoustonSt 7y agoAs others have mentioned, they have ways of writing OCaml specifically to not trigger the GC or perform any excessive allocations. Helps when you have your own version of the compiler and a branch of the language itself. This is talked about with an example in this talk around 18m30s: https://www.youtube.com/watch?v=BysBMdx9w6k https://www.youtube.com/watch?v=BysBMdx9w6k Also as someone else mentioned, Jane Street doesn't try regularly competing (to my knowledge as someone in the industry) at trading horizons that demand lowest the lowest possible latency.
- ironSkillet 7y agoI feel like the jane street tech blog has exceptionally good quality, with a really nice mix of academic and practical ideas thrown in. Do you happen to know of any other video series with this kind of exposition?
- AllanHoustonSt 7y agoUnfortunately I agree with you Jane Street's tech blog and published lecture series are great and probably the best I know of. They make for great advertising to boot. Lecture series like Jane Street's are common in larger trading firms (more than 100-150 headcount) but I haven't seen one of JS' caliber yet. If you welcome general corporate blogs, I think Google AI's technical blog is quite good. Their frequent publications on distributed computing strike a good balance of academic and practical ideas: https://ai.googleblog.com https://ai.googleblog.com Cloudflare also has one of my favorite more engineering focused blogs.
- codingslave 7y agoThey fill up with a few TBs of RAM and then turn off garbage collection. Always surprised people dont know about this.
- potatoyogurt 7y agoIf you don't allocate, you won't garbage collect. GC pauses would be really bad, but you can avoid them, or at least avoid them happening at bad times, if you're careful. It does requires knowing in some detail how Ocaml manages memory.
- jnordwick 7y agoIve worked a couple java based hft platforms at major firms. You write code that never gcs after startup. That means not using certain language constructs and rewriting almost every library along with using off heap memory. I have personally worked on systems that would run an entire week between deployments and never gced.
- giu 7y agoCould you maybe elaborate more on how to achieve this with Java, i.e., run an entire week and never get GCed? I would imagine that using immutable types is one of the tricks used in such a scenario.
- Pepe1vo 7y agoYou would (among other techniques) use something like Stormpot to maintain Object pools to release and acquire instances from. Object pools typically can't match the GC on latency and throughput, however they do provide a lot more predictable and stable performance.
- mlrtime 7y agoYou basically write Java as C++, you don't use any builtins, write everything yourself from pure java.
- dirtydroog 7y agoAnd I'd imagine sun.misc.Unsafe is used quite often too.
- spugody 7y agoI know you said "almost" but you don't have to re-write huge amounts to achieve zero gc and very low latency. There are open source tools, eg. agrona, aeron, that get you a lot of the way there.
- zerr 7y agoWhy would you do that? Why not use C++? Especially, as you say, when memory management is ignored...
- Arnt 7y agoGC pauses aren't inherent. I've written a java compiler that does GC and watched that part work; no pauses even for data structures with loops, and generally excellent performance. Not released yet, because I've also watched other parts not work. But GC without pauses: That worked. And I was relieved² when I saw that my ivory tower worked, after many people had told me it couldn't possibly ;)
- lordnacho 7y agoWorked in HFT and funds, there's a bit more to the taxonomy: - Trading completely based on the current prices. If you're doing purely arbitrage, eg looking for the ask to go under the bid (elsewhere), you are gonna have to be really, really fast, because that kind of thing is so very obvious nobody hasn't thought of it. - One step from from that is passively leaving an order in and hoping for the same thing. Eg you leave a bid in a less liquid market, below the bid in the main market, and hope someone hits you. You then immediately throw that onto the main market. Gotta be super fast to do that, because of course everyone else can see someone traded. - Market making based on some form of ML on the orderbook, basically imbalance. Here you need to do more than just comparing two prices. You also aren't entirely leaning on the current price to offload your position, you might hold onto your position a bit. So now there's risk involved, and you might need to decide how big a position you want. And not everyone will have the same position, so not everyone is after the same trade. - Market making based on multiple orderbooks. Say you have an ETF basket, and you want to be able to make bids and offers around it, as well as the underlying shares. So then you have a different position to everyone else, there's a fair bit more information to digest, and there's a fair bit more modelling which will mean different participants have different decisions. This means your decisions will not be contested in the same way that obvious arbitrage would be.
- nailer 7y ago> how does a market making latency arb firm handle GC pauses that are inherent with any GC language? Don't garbage collect, or do it at the end of the trading day. There's plenty of VMs designed for this, at least in the JVM space (which is where my personal experience has been). RAM is cheap. Latency is expensive.
- gbronner 7y agoPreallocate all of the memory on the box, and control GC runs. There's an entire library of tricks for ensuring that GC pauses don't affect trading, but the biggest one is to use userspace allocated memory pools.
- throwaway992293 7y agoInteresting fact about the presenter (who is also my former boss) that I learned a few days ago: he recently gave $1,000,000 to an anti-Bernie Sanders super PAC. [redacted]
- lend000 7y agoThe prevailing wisdom on Wall Street is that an anti-capitalist would be devastating to the economy, so this should be no big news. Keep in mind that quant firms like Jane Street aren't necessarily long-biased on their positions, so it's likely ideologically motivated.
- akhilcacharya 7y agoAlso it is indeed possible to be pro-Biden and not just anti-Sanders.
- throwaway992293 7y agoI have no doubt that a Sanders presidency would have a negative effect on Wall Street profits (which is why you see people like Ron giving millions of dollars to prevent it) but that's hardly a measure of the health of "the economy."
- lend000 7y agoPerhaps you misunderstood what I said by long-biased, but companies like Jane Street, Two Sigma, RenTech will be just fine (and will probably adapt better than most) to structural changes and a decline in growth of the economy. The tax rates will hit individuals, but probably not as much as his donation set him back, so it's almost certainly ideological. Clearly you are passionate about Sanders, and that's fine, but it seems you are slandering this guy for no good reason.
- smabie 7y agoI dunno, the trading tax Sanders is proposing would hurt these firms a lot more than a traditional hedge or mutual fund. Moreover, it's banks that would be hit the hardest, and they have less exposure to beta than even the market neutral buyside guys.
- codingslave 7y agoSeems to me that firms like two sigma and jane street form some sense of "mystique" about them with regards to how elite their developers are. But once you get inside, most people are writing run of the mill software. Google has the same tactic, even paying below market rates to people willing to work their for the brand. Jane Street does pay very well, but still, most of their hiring is based off of prestigious colleges, less off of people who have written brilliant software. Not that they arent smart. I've just seen enough marketing, and met too many people working at these firms to give them much credit from an "elite software" perspective.
- ironSkillet 7y agoWith so much money on the line, hedge funds and other trading firms focus a lot of effort on marketing and building up a perception that they truly are something special (at least those that take outside client money). Internally, things could be rather mundane, and even downright awful (from a technology perspective). Not commenting on Jane Street in particular, just the industry in general. Source: I've worked at a hedge fund and I've seen how the sausage is truly made. Many friends have told me similar stories about other firms.
- codingslave 7y agoYeah worked in the industry as well, there's a story an older buddy used to tell when he worked at PIMCO in the 90s. Bit different than a quant fund but still applies. They hired a few Harvard Economics PhDs, who when looking at their macro economics material for institutional investors, claimed it was all wrong/didn't make sense. Bill Gross, the fund manager, told them it was to "get the money in the door from the fucking clients, we make gut bets on the market". Then fired the guy
- fnord123 7y ago>Harvard Economics PhDs tbf, academia is its own racket.
- 7y ago
- jasone 7y agoThis is the third time I've watched this video (admittedly with a bit of distraction today). After the first time I went off and learned about modular implicits, which appear to be a huge ergonomic improvement, especially the way the JaneStreet library APIs are designed. The second and third times I got increasingly sad that so much brain power is being sucked up by algebraic effects, to the detriment of other advancements. Oh well, that's their decision to make; JaneStreet continues to do huge service to OCaml in myriad ways, and I really value these tech talk videos as part of that.