HackerTrans
トップ新着トレンドコメント過去質問紹介求人

hmpc

no profile record

投稿

The fastest Linux timestamps

hmpcabral.com
71 ポイント·投稿者 hmpc·3 か月前·18 コメント

The machines are fine. I'm worried about us

ergosphere.blog
21 ポイント·投稿者 hmpc·3 か月前·3 コメント

Vtables Aren't Slow (Usually)

louis.co.nz
1 ポイント·投稿者 hmpc·3 か月前·0 コメント

Two studies in compiler optimisations

hmpcabral.com
128 ポイント·投稿者 hmpc·4 か月前·21 コメント

The C++ input iterator pitfall

hmpcabral.com
3 ポイント·投稿者 hmpc·5 か月前·0 コメント

Making Waffles with Group Theory

hmpcabral.com
1 ポイント·投稿者 hmpc·5 か月前·0 コメント

コメント

hmpc
·2 か月前·議論
Similarly, if not performance-focused, I can wholeheartedly recommend Building Git[0], which walks you through building your own git clone in Ruby (although the language is immaterial).

[0]: https://shop.jcoglan.com/building-git/
hmpc
·3 か月前·議論
It's definitely possible to do correctly, but looking through the code for both crates it doesn't look like they take the necessary precautions (issuing a fence or using RDTSCP). Which is a little weird because at least quanta explicitly checks for RDTSCP support, but then doesn't seem to use it.

(I'm not a Rust expert and I'm on my phone though, so I might be missing something.)
hmpc
·3 か月前·議論
Thanks for sharing this! I hadn't seen it before, I'll definitely add a mention in the post.

This approach is a smart way to get the same precision as the kernel without tying it to the vDSO implementation as in the post, so presumably someone at Google was worried about very similar issues. I also considered an implicit automatic refresh, but ultimately for my purposes controlling when to take the hit was more important than the slight increase in API complexity introduced by an explicit call.
hmpc
·3 か月前·議論
This is explicitly called out in the post as well as the Intel instruction manual. Every codebase I've ever seen that reads the TSC either issues an LFENCE or uses RDTSCP.

In my benchmarks RDTSCP has a slight advantage, despite the slower latency on paper, because it doesn't fully serialise the instruction stream (later instructions can start executing, unlike with LFENCE). Whether the ECX clobber will outweigh that will depend on the situation.
hmpc
·3 か月前·議論
You might've misunderstood the requirements. The time scale was 1-10 micros per component; 100 ns was the overhead per span we were aiming for.

In this case distributed tracing absolutely was the right choice. These were not simple computational tasks. The components were highly stateful and interconnected both on- and cross-host. Between this and the timescale, as well as the volume of events and the dollar-value impact of each potential failure (of which there were many), we needed real-time analysis capabilities, not a profiler.
hmpc
·3 か月前·議論
Yep, I should probably have mentioned this option for completeness. In practice, however, it only saves you a few cycles/nanos and adds more complexity and failure points downstream.
hmpc
·3 か月前·議論
Check the specification at the top. The range for x is [-1, 1]. For the range you provided the accuracy of the 0.5x alternative is reported as only 33%: https://herbie.uwplse.org/demo/570b973df0f1f4a78fe791858038a...
hmpc
·4 か月前·議論
It depends on your use case, as always. Correctness is not always black and white (hence my favourite compilation flag, -funsafe-math-optimizations) and time complexity can be misleading (O(log N) with a large base is O(1) in practice), but a correct, theoretically optimal algorithm might still be leaving a lot of performance on the table. If you're a hyperscaler, a high-frequency trader, or perhaps a game programmer pushing the limits of the platform, small gains can accumulate meaningfully, as can the thousand cuts caused by small inefficiencies spread out over the codebase.
hmpc
·4 か月前·議論
There's an interesting comment on this over on Lobsters: https://lobste.rs/s/e4y5ps/two_studies_compiler_optimisation...
hmpc
·4 か月前·議論
(Author here)

>It all seems very brittle, though. And that something has gone very wrong with our ecosystem of tools, languages, and processes when it becomes advisable to massage source until specific passes in a specific version LLVM don't mess things up for other passes.

I would say the main takeaway is actually to not do that, precisely because it's brittle, difficult to understand, and can backfire by making things harder for the compiler. As I point out at the end, the vast majority of developers will be better served by sticking to common idioms and making their intent as clear as possible using language facilities, rather than trying to outsmart the compiler or, conversely, relying excessively on the optimiser as a magic black box.

That being said, I do find it helpful to understand the broad strokes of the optimisation pipeline (things like "callees are optimised before callers", "maintaining invariants enables more simplifications", or "early simplifications are better") to make the most of it. Like with any other tool, mastery means letting it do its job most of the time but knowing when and where to step in if necessary.