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.

C++ patterns for low-latency applications including high-frequency trading

389 pointsby chris_overseas10 months ago

13 comments

nickelpro10 months ago
Fairly trivial base introduction to the subject.<p>In my experience teaching undergrads they mostly get this stuff already. Their CompArch class has taught them the basics of branch prediction, cache coherence, and instruction caches; the trivial elements of performance.<p>I&#x27;m somewhat surprised the piece doesn&#x27;t deal at all with a classic performance killer, false sharing, although it seems mostly concerned with single-threaded latency. The total lack of &quot;free&quot; optimization tricks like fat LTO, PGO, or even the standardized hinting attributes ([[likely]], [[unlikely]]) for optimizing icache layout was also surprising.<p>Neither this piece, nor my undergraduates, deal with the more nitty-gritty elements of performance. These mostly get into the usage specifics of particular IO APIs, synchronization primitives, IPC mechanisms, and some of the more esoteric compiler builtins.<p>Besides all that, what the nascent low-latency programmer almost always lacks, and the hardest thing to instill in them, is a certain paranoia. A genuine fear, hate, and anger, towards unnecessary allocations, copies, and other performance killers. A creeping feeling that causes them to compulsively run the benchmarks through callgrind looking for calls into the object cache that miss and go to an allocator in the middle of the hot loop.<p>I think a formative moment for me was when I was writing a low-latency server and I realized that constructing a vector I&#x2F;O operation ended up being overall slower than just copying the small objects I was dealing with into a contiguous buffer and performing a single write. There&#x27;s no such thing as a free copy, and that includes fat pointers.
评论 #40913993 未加载
评论 #40914617 未加载
评论 #40911758 未加载
评论 #40912535 未加载
评论 #40917176 未加载
评论 #40923812 未加载
twic10 months ago
My emphasis:<p>&gt; The output of this test is a test statistic (t-statistic) and an associated p-value. The t-statistic, also known as the score, is the result of the unit-root test on the residuals. A more negative t-statistic suggests that the residuals are more likely to be stationary. The p-value provides a measure of the probability that the null hypothesis of the test (no cointegration) is true. <i>The results of your test</i> yielded a p-value of approximately 0.0149 and a t-statistic of -3.7684.<p>I think they used an LLM to write this bit.<p>It&#x27;s also a really weird example. They look at correlation of once-a-day close prices over five years, and then write code to calculate the spread with 65 microsecond latency. That doesn&#x27;t actually make any sense as something to do. And you wouldn&#x27;t be calculating statistics on the spread in your inner loop. And 65 microseconds is far too slow for an inner loop. I suppose the point is just to exercise some optimisation techniques - but this is a rather unrepresentative thing to optimise!
sneilan110 months ago
I&#x27;ve got an implementation of a stock exchange that uses the LMAX disruptor pattern in C++ <a href="https:&#x2F;&#x2F;github.com&#x2F;sneilan&#x2F;stock-exchange">https:&#x2F;&#x2F;github.com&#x2F;sneilan&#x2F;stock-exchange</a><p>And a basic implementation of the LMAX disruptor as a couple C++ files <a href="https:&#x2F;&#x2F;github.com&#x2F;sneilan&#x2F;lmax-disruptor-tutorial">https:&#x2F;&#x2F;github.com&#x2F;sneilan&#x2F;lmax-disruptor-tutorial</a><p>I&#x27;ve been looking to rebuild this in rust however. I reached the point where I implemented my own websocket protocol, authentication system, SSL etc. Then I realized that memory management and dependencies are a lot easier in rust. Especially for a one man software project.
评论 #40910420 未加载
评论 #40914091 未加载
评论 #40910861 未加载
评论 #40911548 未加载
评论 #40910572 未加载
评论 #40915662 未加载
评论 #40910520 未加载
jeffreygoesto10 months ago
Reminds me of <a href="https:&#x2F;&#x2F;github.com&#x2F;CppCon&#x2F;CppCon2017&#x2F;blob&#x2F;master&#x2F;Presentations&#x2F;When%20a%20Microsecond%20Is%20an%20Eternity&#x2F;When%20a%20Microsecond%20Is%20an%20Eternity%20-%20Carl%20Cook%20-%20CppCon%202017.pdf">https:&#x2F;&#x2F;github.com&#x2F;CppCon&#x2F;CppCon2017&#x2F;blob&#x2F;master&#x2F;Presentatio...</a>
评论 #40910251 未加载
winternewt10 months ago
I made a C++ logging library [1] that has many similarities to the LMAX disruptor. It appears to have found some use among the HFT community.<p>The original intent was to enable highly detailed logging without performance degradation for &quot;post-mortem&quot; debugging in production environments. I had coworkers who would refuse to include logging of certain important information for troubleshooting, because they were scared that it would impact performance. This put an end to that argument.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;mattiasflodin&#x2F;reckless">https:&#x2F;&#x2F;github.com&#x2F;mattiasflodin&#x2F;reckless</a>
munificent10 months ago
<i>&gt; The noted efficiency in compile-time dispatch is due to decisions about function calls being made during the compilation phase. By bypassing the decision-making overhead present in runtime dispatch, programs can execute more swiftly, thus boosting performance.</i><p>The other benefit with compile-time dispatch is that when the compiler can statically determine which function is being called, it may be able to inline the called function&#x27;s code directly at the callsite. That eliminates <i>all</i> of the function call overhead and may also enable further optimizations (dead code elimination, constant propagation, etc.).
评论 #40911982 未加载
评论 #40910449 未加载
评论 #40910204 未加载
globular-toast10 months ago
Is there any good reason for high-frequency trading to exist? People often complain about bitcoin wasting energy, but oddly this gets a free pass despite this being a definite net negative to society as far as I can tell.
评论 #40910275 未加载
评论 #40911582 未加载
评论 #40910146 未加载
评论 #40909995 未加载
评论 #40910149 未加载
评论 #40910373 未加载
评论 #40910764 未加载
评论 #40910026 未加载
评论 #40909973 未加载
评论 #40912318 未加载
评论 #40912083 未加载
评论 #40910597 未加载
评论 #40911566 未加载
评论 #40911077 未加载
astromaniak10 months ago
Just in case you are a pro developer, the whole thing is worth looking at:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;CppCon&#x2F;CppCon2017&#x2F;tree&#x2F;master&#x2F;Presentations">https:&#x2F;&#x2F;github.com&#x2F;CppCon&#x2F;CppCon2017&#x2F;tree&#x2F;master&#x2F;Presentatio...</a><p>and up
ykonstant10 months ago
I am curious: why does this field use&#x2F;used C++ instead of C for the logic? What benefits does C++ have over C in the domain? I am proficient in C&#x2F;assembly but completely ignorant of the practices in HFT so please go easy on the explanations!
评论 #40944874 未加载
ibeff10 months ago
The structure and tone of this text reeks of LLM.
poulpy12310 months ago
the irony being that if something should not be high frequency, it is trading
apantel10 months ago
Anyone know of resources like this for Java?
评论 #40955882 未加载
gedanziger10 months ago
Very cool intro to the subject!