A Rust optimization story
quickwit.io
quickwit.io
Regardless, it's neat to see the two languages are so close in performance here. I wonder if down the line, the richer information about lifetimes, etc. that Rust provides will allow optimizations beyond those available to C++ -- or if this is already the case.
[0] https://godbolt.org/z/Mj7PWevex [1] https://bit.ly/3CawbUe
That is, for stack objects, LLVM/etc already do this and lifetimes don't add any useful new information. A function will generally adjust the stack pointer once to allocate and free space for all its locals together.
Beyond that, lifetimes are answering the wrong question. For one thing, the language goes to great lengths to squash and stretch lifetimes to accept more programs- so function signatures are typically as general as possible (IOW they capture as little lifetime information as possible). This even includes entirely "forgetting" information about how/where things are allocated.
Actually using lifetimes or "regions" to control or track allocations probably makes more sense in a higher-level, perhaps more allocation-happy, language. You might be interested in looking at Vale, for example: https://vale.dev/
https://stackoverflow.com/questions/38571270/can-rust-optimi...
Edit: This answer is pretty old, so it may have changed by now, but I couldn't find anything more recent in a quick search
You can just assume you don't miss the cache of course.
What happened here in this blog post is the code was relying on a higher-level optimization that compilers aim to hit, but necessarily cannot in every case: things like vectorization, loop unrolling, or branch elimination, are keyed on heuristics that frequently change. In general this is not a big deal, because the compiler will pick something reasonable, but in the hottest sections of your code this kind of thing can kill performance. When people say they can beat a compiler, it's these kinds of places where you'd do it, and in that point I do agree that compiler optimizations can be limited in their benefit.
IMO (which is heavily biased towards "zero-overhead abstractions") this is still a strong showing for smart compilers. In 99% of cases, the compiler gives you what you want with less code, and then you profile to find the spots where it needs a bit of help.
... But I do wish I had some knobs in stable to hint the compiler in rust.
Mark a condition as unpredictable, a branch as likely, a loop as likely to be long, etc.
Some of it exists as intrinsics but this is not accessible in stable rust.
The term "index" is used because of an analogy to the index of a book. But the so-called "inverted" index is the same way round as a book's index: you look up a word and it gives something analogous to page numbers.
- someone introduced the term "inverted file" for this sort of thing (which is sensible terminology)
- later people started considering these things to be a sort of database index
- so they started saying "inverted index" without paying attention to what that implies as an English phrase
https://books.google.com/books?id=O0AwAQAAMAAJ&pg=PA422&dq=%...
I don't think that's the same thing at all.
In this particular case (assuming SIMD can make 4 comparisons at once), we have an array with 128 elements. So we can compare the needle with indices {24, 48, 72, 96} in one CPU cycle; so we narrow down to approx 24 elements in 1 cycle. Repeat this until we get the answer.
This^ is a very approximate idea. There are a lot of edge-cases and things to consider. But couldn't we solve this problem in 4-5 cycles with SIMD binary search?
To me it's perfectly intuitive.
However, the other example he gave blew me away:
return if cond { ... } else { ... }
The compiler evaluating both results and chosing the right one using a cmov, rather than using a branch to evaluate just one result. My how times have changed.The tantivy binary search & rust binary search only has one different at the end, knowing the size of the slice ahead of time, right?
Could the rust compiler infer the size ahead of time?
> Please follow me in my rabbit hole.
... means something rather different to what you intended, which is probably,
> Please follow me down the rabbit hole.
But thank you for the giggle. :-)
Anyway, RabbitMQ was so unreliable that they ended up having a 'Rabbit Watcher' service, devoted to monitoring Rabbit and alerting them when it went down. And when that service proved unreliable, they added a Rabbit Watcher Watcher. Presumably it was when that service failed that they finally decided to ditch RabbitMQ...
I can't believe the same nonsense exists elsewhere. ours is nothing to do with rabbitmq
What else would it possibly mean?