frontpage.
newsnewestaskshowjobs

Open Source @Github

fp.

Open in hackernews

Faster binary search: from compiled code to mechanical sympathy

https://pythonspeed.com/articles/branchless-binary-search/
24•enz•5d ago

Comments

pillmillipedes•5d ago
I think putting the buckets in eytzinger layout might help with cache locality here? though on the other hand they might all fit into cache anyways..

I'd also want to try interpolation search for this (not necessarily linear interpolation since we're doing floats) - you can take much better guesses than "it's in the middle somewhere" by not having to look at the data through a 1-bit-wide pinhole as comparison algorithms do.

itamarst•5d ago
Better guesses reduce the number of guesses, so there will be less branch misprediction, but there will still be mispredictions for each remaining branch. So I would guess branchless interpolation search would still help.

In practice because the real code in scikit-learn is used in parallel, memory bandwidth starts being a problem in real usage. Plus, in the overall algorithm (this is just a small part) the time spent on binary search is now low enough that there are other, more significant bottlenecks elsewhere. So in practice the branchless optimization had enough impact on the original motivating code base that there didn't seem much point spending more time on it.

moi2388•5d ago
“ How do you speed up computational Python code? A common, and useful, starting point is”

A better starting point is: use a better language. Python is terrible and unbearably slow. If you need anything serious or performant, switch to something else.

wrsh07•58m ago
Literally bullet 2:

> 2. Use a compiled language to write a Python extension.

It's fine to be grumpy about languages, but python is the de facto standard in many industries, and a lot of people don't get to choose.

So, yes, asking "how do you speed up computational python code?" is a good, fine, normal question.

wrsh07•50m ago
I'm somewhat curious about the initial problem:

> Consider the following real problem, one of the steps in scikit-learn’s gradient histogram boosting algorithm:

> You have a large array of floating point numbers.

> You want to assign them to the integer range 0-254, spread out evenly.

Naively I would consider sorting the initial array and then using something like `batched` from itertools to chunk them into the 255 buckets - binary search will give you a bunch of random accesses, and sorting can be cache-oblivious (eg efficient for arbitrary data sizes)

But I'm somewhat concerned I don't fully understand the underlying problem being solved with this step, so I might be misunderstanding the intended result

itamarst•47m ago
The bucket boundaries are often chosen from a random sample of the data, if the input data is very large. Sorting is O(nlogn) on, but using binary search per value to assign a bucket is O(n). So once you hit a large enough number of values this scales better.

Binary search does give random access but in this case there's only up to 255 buckets typically, so it's random access on cached memory.

itamarst•44m ago
When this was posted to lobsters someone shared this relevant link: https://curiouscoding.nl/posts/static-search-tree/
rkagerer•26m ago
This bit is interestingly unintuitive - to go faster, do more iterations:

> As far as the number of while loop iterations, I’m instead going to iterate a fixed number of times, log2 of the number of buckets. For some value this might involve a bit more work, if previously the bucket would be found in an iteration or two, but the saving in speed from avoiding branch mispredictions will make it worth it.

AWS: Inaccurate Estimated Billing Data – $1.7 billion

473•nprateem•6h ago•307 comments

Mozilla: The state of open source AI

https://stateofopensource.ai/
127•rellem•1h ago•68 comments

First atmosphere found on Earth-like planet in habitable zone of distant star

https://www.bbc.com/news/articles/cy4kdd1e0ejo
85•neversaydie•2h ago•66 comments

Claude Code: Anatomy of a Misfeature

https://www.olafalders.com/2026/07/17/claude-code-anatomy-of-a-misfeature/
75•oalders•1h ago•36 comments

Show HN: Watch bots interact with an SSH honeypot in real time

https://honeypotlive.cc/
60•tusksm•2h ago•20 comments

A Road to Lisp: Which Lisp

https://scotto.me/blog/2026-07-17-which-lisp/
55•silcoon•2h ago•20 comments

AI Meets Cryptography 2: What AI Found in OpenVM's ZkVM

https://blog.zksecurity.xyz/posts/openvm-bugs/
36•duha•2h ago•0 comments

Three ways people respond to a problem (other than solving it)

https://improvesomething.today/responses-to-problems/
49•surprisetalk•2h ago•14 comments

Kimi K3, and what we can still learn from the pelican benchmark

https://simonwillison.net/2026/Jul/16/kimi-k3/
26•droidjj•2h ago•3 comments

Show HN: Explore the Workspaces of Modern Creators

https://workspaces.xyz/
14•ryangilbert•41m ago•12 comments

Multi-Primary Color Display Emerges as Next-Gen Color Reproduction Technology

https://en.ubiresearchnet.com/multi-primary-color-display-technology-2026/
46•ksec•3h ago•38 comments

Manufact (YC S25) Is Hiring a Senior infra engineer to build the MCP cloud

https://www.ycombinator.com/companies/manufact/jobs/Dh6PYP5-senior-infrastructure-engineer
1•luigipederzani•2h ago

More Bounce to the Ounce

https://mceglowski.substack.com/p/more-bounce-to-the-ounce
29•pavel_lishin•2h ago•2 comments

EEG shows brain can simultaneous encode two speech streams

https://journals.plos.org/plosbiology/article?id=10.1371/journal.pbio.3003876
206•giuliomagnifico•10h ago•130 comments

Apple targets dozens of OpenAI employees with legal letters

https://www.ft.com/content/1b8c9d52-88a9-426b-ba47-f1811f859166
217•merksittich•4h ago•160 comments

Pebble Mega Update – July 2026

https://repebble.com/blog/pebble-mega-update-july-2026
215•crazysaem•12h ago•122 comments

PennyLane is an open-source quantum software platform for quantum

https://github.com/PennyLaneAI/pennylane
24•donutloop•2h ago•2 comments

Show HN: On-chain bond market where the issuers are AI agents

https://selbonds.now
9•griffinfoster7•1h ago•7 comments

VulnHunter: Capital One's agentic AI code security tool

https://www.capitalone.com/tech/open-source/announcing-vulnhunter/
26•medina•3h ago•16 comments

How Has Roman Concrete Lasted for Millennia? 1,900-Year-Old Latrine Offers Clues

https://www.smithsonianmag.com/smart-news/how-has-roman-concrete-lasted-for-millennia-a-1900-year...
219•divbzero•12h ago•170 comments

Microsoft Comic Chat is now open source

https://opensource.microsoft.com/blog/2026/07/16/microsoft-comic-chat-is-now-open-source/
758•jervant•1d ago•161 comments

Faster binary search: from compiled code to mechanical sympathy

https://pythonspeed.com/articles/branchless-binary-search/
24•enz•5d ago•8 comments

Camera Chase Vehicle

https://transistor-man.com/gimbal_camera_rover.html
115•geerlingguy•1w ago•12 comments

Show HN: Simulator for a custom 8-bit discreet logic computer

https://msap2.mehran.dk
4•mehrant•3d ago•0 comments

Decoy Font

https://www.mixfont.com/experiments/decoy-font
645•ray__•1d ago•146 comments

Tannakian Reconstruction

https://bartoszmilewski.com/2026/07/14/tannakian-reconstruction/
15•ibobev•3d ago•0 comments

Kimi K3: Open Frontier Intelligence

https://www.kimi.com/blog/kimi-k3
1890•vincent_s•1d ago•1115 comments

An Engineer's Guide to USB Typе-С (2024)

https://www.ti.com/lit/eb/slyy228/slyy228.pdf?ts=1759892558029
253•gregsadetsky•6d ago•43 comments

Evidence of inconsistencies in evaluation process and selection of winners

https://www.kaggle.com/competitions/kaggle-measuring-agi/discussion/724918#3498423
395•twerkmeister•4h ago•239 comments

$100 AI Music Video: Claude Fable 5 vs. GPT-5.6 Sol

https://www.tryai.dev/blog/ai-music-video-arena-claude-vs-gpt-5.6
352•hershyb_•20h ago•472 comments