frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Your code is fast – if you're lucky

https://tiki.li/blog/lucky_code.html
56•chrka•3h ago

Comments

jdw64•58m ago
I really envy programmers who are so skilled at this kind of low-level optimization.

The same meaning, but different performance based on notation—it's ultimately about entering LLVM's optimization pass, which likely comes down to differences in the internal IR pattern. It almost feels like a difference in innate talent...

I feel like I can build CRUD applications well enough, but I still seem to be weak at low-level processing.

Where can I learn these kinds of techniques? I'd appreciate any book recommendations.

po1nt•52m ago
I personally learned a lot from cpp conference videos. I would highly recommmend it.
jdw64•47m ago
I should study that. Thank you
khuey•34m ago
I'm not sure it's a "technique" but the general insight worth taking away from this is that compiler authors often write optimizers to recognize specific patterns so writing your code in a more idiomatic form increases the odds an optimizer will be able to optimize it.

In this specific instance, at the hardware level it helps to understand how the branch predictor works and why quicksort in particular is essentially the worst case for the branch predictor, and then you'll understand why the cmov/csel optimization is such a big win.

jdw64•26m ago
About that kind of 'technique', I guess I should make it a habit to dig into the compiler, which is still a black box to me. I should study a few techniques myself. Have a good day
jasonjmcghee•22m ago
Casey Muratori's https://computerenhance.com is a good resource
jdw64•22m ago
thanks!
ivanjermakov•21m ago
Expose yourself to lower level technologies (compilers and optimization techniques, hardware history and design) and let curiosity guide you. Learn how to profile and analyze program performance.
nikhizzle•17m ago
Got to my first job out of college and they gave me core dumps and had me debug the kernel for a year. Not my kind of fun, but definitely got me skilled in the art of low level.
tux3•17m ago
You could read compiler books, but I would actually recommend reading about CPUs and computer architecture directly. If you understand how the hardware works, then the optimizations are all very natural and fit into the picture perfectly, instead of being some arcane compiler magic that you have to take as a disconnected fact.

Personally I actually haven't read too many books on optimizations, I just absorbed information over years one thing at a time, but something like Computer Organization and Design is a pretty good intro to the low-level picture. If you want to drown in extremely dense technical topics that will give you a lot of jumping off points to search, read Agner Fog's microarchicture optimization guide (https://www.agner.org/optimize/). It won't tell you what LLVM is doing, but it'll tell you why it's doing it. Fair warning, it's dense and pretty dry.

Then it depends how interested you are in doing low-level nonsense. If you spend a lot of time writing performance oriented systems code, you'll come to use profiling tools that show you the assembly. If you stare at it long enough, you sometimes start to question why the compiler wrote it this way. And you're naturally led as you try to optimize your code to wonder how LLVM is coming up with this ASM that it spits out and why it sometimes gets it wrong.

There's nothing magical or that requires innate talent. You can learn all of this very naturally if you work close to the metal and take the time to question how the abstraction layer below you actually works. If you keep doing this, you eventually find out it's not that deep, it's just a lot of stuff accumulated over time, but none of it particularly difficult or inaccessible.

vlovich123•10m ago
I also agree that computer architecture is more important - it grounds your understanding of how to write efficient code regardless of platform since most machines today share very similar ideas (OOO execution, caches, NUMA etc).

How ever, I will disagree slightly that all the optimizations compilers do are about optimizing for a given architecture; some transformations are just weird algorithmic black magic about optimizing the underlying code itself. Knowing how to make sure the compiler sees through a given construct to give you the low level expression you want is too much art and randomness; we need better ways to express optimization expectations so that if the compiler fails to match expectations it becomes a loud compiler error.

maCDzP•13m ago
I did Nand2Tetris and then I understod why I need to vectorize. You get a view from nand-gate to software and get to see all the interfaces. Its a wonderful course.
IshKebab•46m ago
Wow that is quite surprising. Almost seems like it could be a compiler bug tbh. Very fragile optimisation if not!
xlii•15m ago
Is it only me..?

Quicksort is supposed to be an algorithm that has O(n) to O(n²) performance and O(n log n) being only an average performance case. Test was made on random data coming from different archs (so I doubt it's characteristic would be remotely identical).

Given input size of 50M it means that performance could be between 50M (5e7) up to 2.5e15. That's like performance instability of 8 orders of magnitude.

I'm not sure here if we can't write instead that "Your code is fast if you picked fast case for it" especially since fix of 6 OOM is smaller than algorithm's performance range.

sashank_1509•9m ago
I’m assuming he measured time by averaging on 100s of instances, or he maintained the exact same input for both versions of code. Would be a big oversight if not!
gmm1990•7m ago
I hope the test data is the same when comparing the different runs. So the big o notation should be the same across different runs.
adgjlsfhk1•5m ago
if you have decent (randomized) pivoting, you never hit the worst case or anything like it
marginalia_nu•4m ago
Looking at big-O isn't very informative. We have plenty of statistical tools for telling whether there is an effect even with noisy data.

Networking and the Internet, from First Principles

https://fazamhd.com/mental-models/networking/
84•faza•1h ago•36 comments

Your code is fast – if you're lucky

https://tiki.li/blog/lucky_code.html
56•chrka•3h ago•18 comments

Semantic/Hybrid Search in the Browser

https://bart.degoe.de/semantic-search-in-your-browser/
8•bartdegoede•1h ago•1 comments

Einstein's relativity rules chemical bonds in heavy elements, new research shows

https://www.brown.edu/news/2026-07-09/chemical-bonds-relativity
306•hhs•15h ago•123 comments

QuadRF can spot drones and see WiFi through my wall

https://www.jeffgeerling.com/blog/2026/quadrf-can-spot-drones-and-see-wifi-through-my-wall/
642•speckx•22h ago•210 comments

Google Search lets creators know more about their reach

https://www.theverge.com/tech/961955/google-search-console-reach-platform-properties
44•herbertl•3d ago•24 comments

Otary – Image and Geometry Python Library Now Has Tutorials

https://alexandrepoupeau.com/otary/learn/
52•poupeaua•3d ago•1 comments

Apple sues OpenAI, accuses ex-employees of stealing trade secrets

https://9to5mac.com/2026/07/10/apple-sues-openai-trade-secret-theft/
1260•stock_toaster•17h ago•680 comments

FCC Approves Test of Space Mirror to Light Night Sky Despite Outcry

https://www.nytimes.com/2026/07/10/climate/fcc-space-mirror.html
36•reaperducer•1h ago•21 comments

An update on residential proxies and the scraper situation

https://lwn.net/SubscriberLink/1080822/990a8a5e2d379085/
245•chmaynard•18h ago•246 comments

An iroh powered smart fan

https://www.iroh.computer/blog/an-iroh-powered-smart-fan
133•surprisetalk•4d ago•36 comments

The mask that compiles to nothing: how HotSpots JIT learned to reason about bits

https://questdb.com/blog/jvm-jit-known-bits/
46•rowbin•5d ago•1 comments

SpaceX wants to launch 100k more Starlink satellites for 100x the bandwidth

https://www.zdnet.com/home-and-office/networking/spacex-wants-to-launch-100000-more-starlink-sate...
227•CrankyBear•20h ago•758 comments

Speculations Concerning the First Ultraintelligent Machine (1965) [pdf]

https://languagelog.ldc.upenn.edu/myl/Good1964.pdf
6•zetalyrae•31m ago•0 comments

Good Tools Are Invisible

https://www.gingerbill.org/article/2026/07/10/good-tools-are-invisible/
490•theanonymousone•1d ago•222 comments

The vintage beauty of Soviet control rooms (2018)

https://designyoutrust.com/2018/01/vintage-beauty-soviet-control-rooms/
151•mvdtnz•8h ago•50 comments

AI 2040: Plan A

https://ai-2040.com/
319•kschaul•1d ago•346 comments

Late Bronze Age Collapse

https://acoup.blog/2026/01/30/collections-the-late-bronze-age-collapse-a-very-brief-introduction/
389•dmonay•1d ago•268 comments

The tech of 'Terminator 2' – an oral history (2017)

https://vfxblog.com/2017/08/23/the-tech-of-terminator-2-an-oral-history/
235•markus_zhang•21h ago•80 comments

Silent speech with ultrasound

https://alephneuro.com/blog/silent-speech
75•chrwn•3d ago•16 comments

Combustion engine web-based simulator

https://combustionlab.net
201•mytuny•5d ago•70 comments

After 7 years in production, Scarf has reluctantly moved away from Haskell

https://avi.press/posts/2026-07-10-after-7-years-in-production-scarf-has-reluctantly-moved-away-f...
177•aviaviavi•1d ago•218 comments

Alternate clock designs and time systems

https://serialc.github.io/altClocks/
172•ethanpil•4d ago•92 comments

Inference Optimization for MiMo v2.5: Pushing Hybrid SWA Efficiency to the Limit

https://mimo.xiaomi.com/blog/mimo-v2-5-inference
96•theanonymousone•4d ago•37 comments

Snails' teeth beats spider silk as nature's strongest material (2015)

https://www.smithsonianmag.com/smart-news/spider-silk-loses-top-spot-natures-strongest-material-s...
210•simonebrunozzi•21h ago•158 comments

GPT-5.6 Sol Ultra produces proof of the Cycle Double Cover Conjecture [pdf]

https://cdn.openai.com/pdf/04d1d1e4-bc75-476a-97cf-49055cd98d31/cdc_proof.pdf
488•scrlk•19h ago•396 comments

Show HN: Getting GLM 5.2 running on my slow computer

https://github.com/JustVugg/colibri
873•vforno•2d ago•218 comments

New York City to ban deceptive subscription practices

https://www.theguardian.com/us-news/2026/jul/10/new-york-city-deceptive-subscriptions-ban
574•randycupertino•19h ago•277 comments

A love letter to flashcards

https://lesleylai.info/en/flashcards/
167•surprisetalk•22h ago•98 comments

Computation as a universal and fundamental concept

https://ergo.org/courses/computation-as-a-universal-and-fundamental-concept
148•simonpure•22h ago•119 comments