Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow to (re)compile #106

Closed
jplatte opened this issue Oct 9, 2020 · 4 comments
Closed

Slow to (re)compile #106

jplatte opened this issue Oct 9, 2020 · 4 comments
Assignees

Comments

@jplatte
Copy link
Collaborator

jplatte commented Oct 9, 2020

@martinetd was surprised by the long (re)compilation times: #104 (comment).

I've played around with this locally because I assumed this comes mostly down to the large amount of generated code in Ruma, but surprisingly the ruma-client hello_world example recompiles in roughly 3 seconds on my machine while the matrix_sdk login example takes almost 6 seconds on average.

Here's some things that could help that I haven't tried yet:

  1. installing LLVMs linker, lld and using that by creating .cargo/config.toml with

    # adjust to whatever target you are building for
    [target.x86_64-unknown-linux-gnu]
    rustflags = [
        "-C", "link-arg=-fuse-ld=lld",
    ]
  2. building all dependencies in release mode, which may reduce the size of intermediary artifacts and thus improve relinking time, by adding the following to the Cargo.toml of a project using matrix_sdk (this won't work in the workspace itself because it doesn't apply to workspace crates):

    [profile.dev.package."*"]
    opt-level = 2

    (for more info see the Cargo Book)

Separately from that, I've been thinking about having feature flags in Ruma such that you could choose to only have request-sending + response-receiving generated rather than getting all of request-{sending,receiving} + response-{sending,receiving}.

@jplatte jplatte self-assigned this Apr 8, 2022
@jplatte
Copy link
Collaborator Author

jplatte commented Jun 1, 2022

So it looks like at least in debug mode, most of the time is spent on linking when recompiling the login example after touch examples/login.rs. On my machine, it took >7s with the default linker, and 1.64s with mold.

Unfortunately, this means we probably can't do much about the recompilation times of projects using the Matrix Rust SDK, outside of suggesting the use of a faster linker.

There's also been many issues with the compilation times (and compiler memory usage) when working on the SDK though, I might look into that too, soon-ish.

@martinetd
Copy link
Contributor

Thanks, that's already a great improvement just from switching linker! I'll give it a try :)

Iirc my second problem was large types (had to add a type_length_limit directive at top of the sources) that I had read could be slow at the time... I'm not sure if that improved or if I still need to look into putting a key element in a Box to break the chain somewhere; I've honestly not touched at my client for a while now...

@jplatte
Copy link
Collaborator Author

jplatte commented Jun 1, 2022

Here's what you need for mold (lld is also be faster than the gnu linker, but not nearly as fast as mold):

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = [
    "-C", "link-arg=-fuse-ld=mold",
]

@jplatte
Copy link
Collaborator Author

jplatte commented Jun 20, 2022

I'll close this issue since it isn't really actionable. We'll definitely keep an eye on compile times though, some recent improvements in that area are over at #778.

@jplatte jplatte closed this as completed Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants