Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Performance concern regarding print function #2

Closed
UE2020 opened this issue Aug 6, 2021 · 6 comments
Closed

Performance concern regarding print function #2

UE2020 opened this issue Aug 6, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@UE2020
Copy link

UE2020 commented Aug 6, 2021

The print function does not seem to implement block buffering. So if you print a lot of lines, you end up calling the write syscall for every line, which is quite costly.

@Alonely0
Copy link
Owner

Alonely0 commented Aug 6, 2021

false, print function collects all args and then prints them in a single syscall

// mitigate printing bottleneck by using only 1 print

@UE2020
Copy link
Author

UE2020 commented Aug 6, 2021

false, print function collects all args and then prints them in a single syscall

// mitigate printing bottleneck by using only 1 print

Line buffering and block buffering are not the same thing. Rust's io::stdout does not do block buffering by default.

rust-lang/rust#60673

@BlueCannonBall
Copy link

In C, setvbuf(stdout, NULL, _IOFBF, 0); can be used to make stdout block buffered. By default, it is line buffered.

@Alonely0
Copy link
Owner

Alonely0 commented Aug 6, 2021

ah lol, didn't know that. Tomorrow I'll patch it

@Alonely0
Copy link
Owner

Alonely0 commented Aug 7, 2021

These are the measures I made:

  • stdout lock + write buffer
    ./target/debug/voila /home/guillem/ "1 == 1 {print(@name: @size=mb)}" -r 62.38s user 15.62s system 91% cpu 1:24.95 total

  • stdout + write buffer
    ./target/debug/voila /home/guillem/ "1 == 1 {print(@name: @size=mb)}" -r 56.35s user 7.84s system 99% cpu 1:04.33 total

  • stdout lock
    ./target/debug/voila /home/guillem/ "1 == 1 {print(@name: @size=mb)}" -r 54.93s user 8.20s system 99% cpu 1:03.28 total

  • just print args joined
    ./target/debug/voila /home/guillem/ "1 == 1 {print(@name: @size=mb)}" -r 55.33s user 8.62s system 99% cpu 1:04.14 total

Stdout lock wins

@Alonely0
Copy link
Owner

Alonely0 commented Aug 7, 2021

98454e7

@Alonely0 Alonely0 closed this as completed Aug 7, 2021
@Alonely0 Alonely0 added the enhancement New feature or request label Aug 7, 2021
@Alonely0 Alonely0 linked a pull request Aug 7, 2021 that will close this issue
Merged
@Alonely0 Alonely0 removed a link to a pull request Aug 7, 2021
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants