On 4/22/13 5:54 AM, Huon Wilson wrote:
Hi all,

I've got a few questions:

There are many instances of functions returning and taking dynamic
trait objects in @ boxes (e.g. all of the io functions, things dealing
with core::rand::Rng, core::run::Program) rather than a plain type
(for return values) or a generic (for arguments), this seems a little
peculiar given it (probably?) has a runtime cost due to the vtables
and the extra GC required. Is this legacy code that hasn't been
updated yet? And, is there a reason for it remain in the dynamic
objects form? (I know there's no point touching the io stuff since it
is all being redone.)

You're correct. The `@` smart pointers in `io` are currently the #1 performance problem with Rust in benchmarks that people write. (They're also responsible for a lot of unsafe code in the benchmarks-game benchmarks that could otherwise be fully safe.) The new `rt::io` module [1] is being designed to avoid this. That module will replace `io` when it's ready.

To give an example, I'm talking about converting items like (all
from core::rand)

     fn Rng() -> @Rng
     fn rand(rng: @rand::Rng) -> Self
     impl RngUtil for @Rng

to

     fn Rng() -> RandRes
     fn rand<R: rand::Rng>(rng: &R) -> Self
     impl<R: Rng> RngUtil for R

Yes, I wanted to do just that at some point. Patches welcome :)

Patrick

[1]: https://github.com/brson/rust/tree/io

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

Reply via email to