Why is calling my asm function from Rust slower than calling it from C?
74 points by ohrv
74 points by ohrv
PSA: if you don’t see syntax highlighting, disable the 1Password extension.
What the hell.
Yep I wasted ages trying to work out why syntax highlighting broke on my website. Not getting a lot of confidence in 1P because of this.
Looking at Bitwarden but open to other suggestions for someone mostly on Apple OSes but appreciates not being locked in.
I use and like KeepassXC+Syncthing, it's fully open source and self sovereign. And once setup, Syncthing can allow syncing other things without counting towards iCloud quota.
On iOS I use Keepassium which is convenient and well integrated with the OS, open source, and has a nice premium licensing model: subscription, or pay once and get new features for a year, after which you keep that set of features "forever".
It's a universal app so you could skip KeepassXC, but I don't use macOS so IDK how good it is there.
And for Syncthing, Synctrain which I discovered via lobsters when it was released earlier this year!
Edit: I guess if you only care about Apple platforms, you can use iCloud instead of Syncthing cause the Keepass DB is small. And file based cloud storage is pretty easy to swap out later.
Keepassium doesn’t support acting as an ssh agent on desktop, right? Kinda shame
Ah too bad. That's a feature I use everyday with XC!
I've had good experiences with making feature requests on GitHub. It's not implemented straight away but the dev replies and and tries to plan things.
I desperately hope that it's only supposed to target content in the extension context and they didn't intend to "helpfully" highlight code on pages. Screwing up the first is embarrassing. The second is a huge, intentional breach of trust, and 1Password is deeply-embedded enough into my life (my personal k8s cluster uses it as the secret source!) that it'd be a royal pain to switch.
the amount of background cursedness in this post is just so damn high lmao
why is it dispatching at runtime between a Rust and an ASM version?
why does the Rust version take different arguments than the ASM version?
why does an extern “C” function take a generic parameter?
why are they using that FFISafe thing instead of allow(improper_ctypes)?
anyway, the research here is cool and the project looks neat, but. man. wow.
IMO we have good reasons for these - having a pure Rust fallback is good because you can’t know if a special asm is available at compile time, which forces a function pointer. When you need a function pointer, avoiding the generic in extern is hard without introducing an indirection that isn’t zero cost. Having stronger types is one of the primary benefits of having a Rust version in the first place, so working with untyped pointer undermines that.
These are all inherent complexities and I think the rav1d codebase really handles them admirably.
I tend to agree that improper ctypes is a bit restrictive, but that’s more of a Rust problem not a library problem.
There are some solutions for converting runtime dispatch into dynamic-load-time resolution. Glibc used to use these so-called GNU IFuncs for the exported performance-sensitive stuff (e.g. memcpy). Nowadays there's some multi-library approach with tuned implementations for different CPU tiers (Glibc hwcaps).
That would be nice, but it seems fiddly and needing specific OS and linkers ;(
Rust ecosystem values libraries that just work with cargo build on any platform. rustc/Cargo also have a difficulty supporting anything non-trivial related to linking due to relying on system/user-specified linkers which are strange beasts without a reliable API and with awful unhelpful error messages.
Presumably, the Rust code is compiled for a generic target that might not have some instructions used in the assembly version.