Unofficial Hacker News companion — get notified on comment replies, and more.

Optimizing Rustc's next trait solver (opens external site)

213 points by g0xA52A2A 6 days ago | donsz.nl | 48 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (4)

  1. In addition to what PudgePacket has said, and although LOC isn't a great proxy for the project complexity, it doesn't seem like you're counting your dependencies' LOC. Serde has more than 20 kLOC and serde_json more than 15 kLOC. serde_derive pulls in syn which has ~50 kLOC and is famously slow to compile.

    Also the point of the release profile is to trade compilation performance for runtime performance (you'd be better off iterating on the dev profile).

    There are also many other details that interfere and can't be inferred from your comment like: what's your OS, which linker are you using, are you using opt-level 3 on C++, which compiler are you using on C++, are you using heavily using templates in C++ or macros in Rust, etc.

    Replies (1)
    1. It is basically same weight in terms of code style.

      I use clang for compiling c++. But I use a custom build system I built on top of it. I compile with -O2 but using -O3 or even -O5 doesn't make much of a difference.

      I tried pretty hard to make sure both projects output small binaries and compile fast.

      I don't depend on serde because I knew it is bloated but didn't know serde_json was so bloated too.

      I am using latest stable rust on linux x86_64 so I assume it is using lld which is what c++ project uses too.

      I don't think there are any template use in either project except things like hashmaps and slices etc. I don't use traits except to interact with dependencies in rust.

      I use a specific structure in C++ so it is not like regular C++ code but that is just basically impossible to do in rust because I would have to write too much unsafe code and it feels mandatory to use RAII in rust.

      Replies (1)
      1. > or even -O5

        -O4 and higher are (currently) equivalent to -O3

        > I don't depend on serde because I knew it is bloated but didn't know serde_json was so bloated too.

        serde_json depends on serde though?

        > I don't think there are any template use in either project except things like hashmaps and slices etc. I don't use traits except to interact with dependencies in rust.

        If you're interested in investigating further it might be worth trying cargo bloat [0] or similar to get a bit more data about what is consuming space. rustc's self-profiling framework [1] might be another way to get data.

        [0]: https://github.com/razrfalcon/cargo-bloat

        [1]: https://github.com/rust-lang/measureme

        Replies (1)
        1. > serde_json depends on serde though?

          Ahhh, of course.

          Thanks for the suggestions.

          Edit: I was able to reduce the output code size to <600KB from the original 1.3MB after exploring the suggestions. It made the release build time a lot longer but it is worth it for my use case.