3 ms·
My understanding of zero-cost abstractions is that rust doesn't have the runtime overhead for things like vtable lookups and calling a function during execution
by jasonjmcghee 3y ago
My understanding of zero-cost abstractions is that rust doesn't have the runtime overhead for things like vtable lookups and calling a function during execution - that many other languages do.
Isn't that concept completely unrelated to this?
Unless I'm misunderstanding the issue and fix, this is performance improvements due to batched operations.
Search for all occurrences, perform necessary processing.
Vs.
if not complete, find next occurrence, perform processing, repeat.
What am I missing?
- noam_k 3y agoI didn't delve too deeply into the code in the post, but no, I wouldn't say that this is example of zero-cost abstractions at all. Zero cost can come in two forms (that come to my mind right now, feel free to comment with more): runtime and memory. You mentioned dynamic dispatch (when calling a vtable method) that _can_ be zero cost when using generics, the compiler will "inline" the type and know what method is being called. Note that there is a compile-time trade-off here, and the binary size would be larger than using `&dyn` (a pointer to a vtable). To illustrate memory zero-cost, consider an optional boolean argument to a program. A boolean has two valid states, but used 8 bits of memory, defining `Option<bool>` would naively use one byte for the discriminant, and another for the value. Rust uses the niche optimization[0] to promise that this type will only use one byte of memory. [0]https://google.github.io/comprehensive-rust/smart-pointers/box.html#niche-optimization https://google.github.io/comprehensive-rust/smart-pointers/b...
- Shish2k 3y agoThe zero-cost abstractions is a bit of a tangent, but connected: Using Electron, running an extremely-optimised search algorithm and displaying results takes 200ms Using Rust, running a hopelessly naieve algorithm takes 1s; but a slightly-optimised-and-still-very-clean algorithm (which is built out of zero-cost abstractions) takes 4ms