Hi everyone,

It occurred to me that our insistence on dynamic linking for the standard library is likely to cause performance problems. This has been lingering at the back of my mind for a while, although my fears have been allayed to some degree so far by the fact that trivial standard library routines rarely show up in profiles. But it occurred to me that there's one small class of functions that we really can't get away with not inlining: simple iterators.

Consider uint::range(). This is the preferred way to do a C-style for loop in Rust. Up to this point we've been preferring to write C-style for loops as while loops, as near as I can tell, due to some early flakiness in rustboot, and for performance reasons.

While loops work fine. But while loops aren't something we want programmers to have to write to get good performance out of their loops. They're a quite low-level construct. I've been burned many, many times while writing Rust code by forgetting to increment the loop counter.

At the moment, *each iteration* of uint::range() requires not one, but two indirect function calls, both across boundaries that are opaque to LLVM (indeed, each boundary is a DLL boundary). This is likely not going to work; we're inhibiting all loop optimizations and forcing new stack frames to be created for every trip around the loop.

I'm pretty sure that LLVM can inline away the overhead of range(), by first inlining the iterator itself, then inlining the for-each body. But, in order to do that, it needs to statically know the iterator definition. So range() can't be dynamically linked anymore. The simplest solution I can think of is to allow both static and dynamic library crates.

There's been a movement lately in some circles to forbid dynamic linking entirely; Go for example explicitly does not support it (in keeping with the Plan 9 tradition). I tend to disagree; I think that supporting dynamic linking is useful to enable memory savings and to make security problems in the wild easy to patch. (I'm told there was a zlib security bug that was much easier to fix on Linux than Windows because Windows apps tend to statically link against everything but the system libraries.) But exclusively relying on it is not going to be tenable; some routines are so simple, yet so critical to performance, that static linking is probably going to be the only viable option.

Thoughts?

Patrick
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to