-
Notifications
You must be signed in to change notification settings - Fork 13.4k
compilation time (of volatile array read?) is super-quadratic in array size #74476
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
A tremendous amount of machine code is generated (depending on |
(Well, the amount of code generated should be linear in |
couldn't this be rewritten as a loop of volatile u64 reads? |
You're right that a loop would be a legal lowering, but I don't think there's a good way to actually generate that within the the context of how CodeGen and especially legalization is done in LLVM today. But I just remembered that "volatile memcpy" is now a thing in LLVM, so perhaps rustc could be modified to emit that for sufficiently large values? But this can call the ordinary |
Thanks etc.Hi again. I'm afraid I don't have much to add in the discussion of My program does not need to do such a large volatile read and I have I thought I would report this as a bug as the behaviour seemed, to me Rust is usually very helpful and forgiving. (Admittedly, here I used I don't know how common this kind of program is. If you have seen What I was trying to doAnyway, in the hope it's useful and/or interesting to you, I'll I used this technique because I was doing some benchmarking and needed I'm not aware of a better way to make a barrier for the optimiser. Ian. [1] Read only if you have a strong stomach: orlp/slotmap#43 (comment) Incidentally I am very impressed with how Rust managed to deal with |
https://docs.rs/bencher/0.1.5/bencher/fn.black_box.html |
Interesting, thanks. That is precisely right except it says it's not guaranteed to actually work :-). |
It's generally considered good enough for benchmarking, you can always look at the assembly output to make sure. |
I ended up (skim)reading a lot of the discussion in the various black_box issues etc. I think what is needed is what is described in this comment: rust-lang/rfcs#1484 (comment) Unfortunately what is provided is something considerably weaker. As documented, In this issue: is it worth trying to make the compiler not quadratic in the size of the volatile array read? Or providing a warning about this or similar situations? If not then I think probably you'll want to close this issue, and sorry for wasting your time. Thanks for your attention. |
I do think we should deprecate and warn about volatile reads and writes like this one. Generally, volatile accesses for aggregates (excluding those that map to architecturally-supported data types, such as |
Hi. I tried this code:
Expected results:
Relatively quick compilation of a program that prints 42.
Actual results:
rustc took 45 seconds on my really rather fast laptop (and also uses a great deal of memory). The compiled binary works as epected.
Changing the value of COUNT shows the following (with an earlier rustc, but the newly-updated one is about as slow):
10000 1.74s
20000 5.9s
30000 20s
40000 46s
I haven't waited for completion of any larger values. In my original version I had COUNT = a million; I killed rustc after some minutes and about 2G of RAM use.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: