Thom Chiovoloni
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# rustc jemalloc futzing *Warning: I ramble a decent amount in this. You've been warned.* So, I did some experimenting based on the comment <https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001>, in a very hacky way -- essentially trying to answer the question of "First probably measure the impact to see whether it's at all worth it.". In particular, macOS doesn't have a good way of overriding the system allocator (some quirks of the malloc zone API causes `free` to be extremely expensive), so I wanted to see if using a `global_allocator` would help there. The TLDR is that on macOS (which aside from perhaps Windows is probably the OS that will benefit from this the most) jumping through those hoops in a hacky (possibly unrealistically hacky? Hopefully not) way leads to around a 3%-5% speedup for `cargo check` and `cargo build`. The branch I did this in is <https://github.com/thomcc/rust/tree/very-hacky-alloc-experiments>, and I mostly did it to see how full of crap I was in the postconf when I went on about the allocator situation in rustc on macOS (answer: at least not *entirely* full of crap, but 5% is less than I expected, although it's not bad for just changing build configuration). Note that very many parts of this are total hacks -- the way I "decoupled `librustc_driver.so` from `libstd.so`" in particular was just to get rid of libstd.so. There's almost no way this is what we actually want (it kills rustdoc, and probably all other tools/anything else using rustc-private APIs). That said, I do think there is a way to combine libstd.so into librustc_driver.so, which is likely the right way to do this. Or maybe not, in which case I misunderstood what the initial comment meant. ## Process Basically, I did the following things: 1. Moved jemalloc and such into `rustc_driver`. 2. Add a `#[global_allocator]` using jemallocator. 3. Tried to "Decouple `librustc_driver.so` from `libstd.so`" in the hackiest way possible, which is to say "remove `"dylib"` from std's crate_type". Doing this breaks rustdoc, and presumably several other things, but rustc seems to function otherwise. I don't think this is how this should be done (actually, I'm 100% it is *not* how this should be done, but doing this correctly probably requires changes to bootstrap and seems like a real pain, and this works for now for getting rough measurements). (Note that I tried several combinations of steps 1, 2, and 3, and it seems like all 3 are needed for there to be any benefit to doing this, at least on macOS) 4. Do some builds. Basically all the numbers are done on an aarch64-apple-darwin machine using a stage1 build with the following config.toml: ```toml profile = "library" changelog-seen = 2 [rust] codegen-units-std = 1 incremental = false jemalloc = true ``` which hopes to be semi-realistic for my platform? It's at least roughly the same speed as my normal nightly toolchain. 5. Get very rough numbers for perf by using hyperfine in the rustc-perf repo. I use macOS mainly (and expect this to be mostly beneficial on macOS), so getting concrete numbers isn't easy for me. Also, this will almost certainly benefit macOS more than other platforms, since it allows rust allocations to bypass the zone deallocator. Also worth noting: There was a lot of flailing with missng symbols, which both motivated switching to `tikv-*` versions of the crates (which are probably the same so this is likely unnecessry), and some hacky changes in rustc_driver to make `#[used]` actually work. I don't think any of this was actually necessary, but if you read the patch you'll see it. ## Numbers Anyway, here's some numbers. They're rough, as mentioned: In all of these `+stage1src` is the baseline (rust-lang/rust @ [`8064a495086c2e63c0ef77e8e82fe3b9b5dc535f`](https://github.com/rust-lang/rust/commit/8064a495086c2e63c0ef77e8e82fe3b9b5dc535f)) and `+stage1` is with my changes (<https://github.com/thomcc/rust/tree/very-hacky-alloc-experiments>). Yeah, the names are weird, it's just the names of the rustup linked toolchains I already had set up. #### Ripgrep ``` $ cd collector/benchmarks/ripgrep-13.0.0 $ hyperfine --warmup 1 --runs 5 --prepare "cargo clean" --cleanup "cargo clean" -L rustc stage1,stage1src -L subcmd check,build "cargo +{rustc} {subcmd}" Benchmark 1: cargo +stage1 check Time (mean ± σ): 5.810 s ± 0.177 s [User: 18.002 s, System: 2.316 s] Range (min … max): 5.670 s … 6.118 s 5 runs Benchmark 2: cargo +stage1src check Time (mean ± σ): 6.147 s ± 0.133 s [User: 18.809 s, System: 2.329 s] Range (min … max): 6.019 s … 6.374 s 5 runs Benchmark 3: cargo +stage1 build Time (mean ± σ): 8.025 s ± 0.239 s [User: 29.187 s, System: 3.245 s] Range (min … max): 7.804 s … 8.364 s 5 runs Benchmark 4: cargo +stage1src build Time (mean ± σ): 8.486 s ± 0.079 s [User: 30.444 s, System: 3.299 s] Range (min … max): 8.404 s … 8.594 s 5 runs ``` This shows around a 5% improvement for both `cargo check` and `cargo build`. This gets drowned out more in `--release` builds, FWIW, but I don't have the numbers. #### Cargo ``` $ cd collector/benchmarks/cargo-0.60.0 $ hyperfine --warmup 1 --runs 5 --prepare "cargo clean" --cleanup "cargo clean" -L rustc stage1,stage1src -L subcmd check,build "cargo +{rustc} {subcmd}" Benchmark 1: cargo +stage1 check Time (mean ± σ): 13.230 s ± 0.307 s [User: 47.052 s, System: 9.785 s] Range (min … max): 12.993 s … 13.766 s 5 runs Benchmark 2: cargo +stage1src check Time (mean ± σ): 13.796 s ± 0.185 s [User: 48.728 s, System: 10.000 s] Range (min … max): 13.611 s … 14.092 s 5 runs Benchmark 3: cargo +stage1 build Time (mean ± σ): 26.540 s ± 0.688 s [User: 91.693 s, System: 13.300 s] Range (min … max): 25.386 s … 27.081 s 5 runs Benchmark 4: cargo +stage1src build Time (mean ± σ): 27.569 s ± 0.479 s [User: 93.950 s, System: 13.341 s] Range (min … max): 26.942 s … 28.136 s 5 runs ``` Less impressive, with 3% for `build` and 4% for `check` #### Externs I'm not sure what this one is (it's whatever [this](https://github.com/rust-lang/rustc-perf/tree/master/collector/benchmarks/externs) is), but we apparently use it as part of our PGO stuff, so I figured I'd run it. It went much faster so I did far more iterations, and even tried with `--release`. Ideally I'd have done this for all of them, probably. That said, it's much faster so seems more sensitive to noise, and I wasn't able to get a run that didn't warn about statistical outliers. Hopefuly the larger iteration count helps compensate for this some ``` $ cd collector/benchmarks/externs $ hyperfine --warmup 5 --runs 20 --prepare "cargo clean" --cleanup "cargo clean" -L rustc stage1,stage1src -L subcmd check,build,"build --release" "cargo +{rustc} {subcmd}" Time (mean ± σ): 244.9 ms ± 51.9 ms [User: 147.8 ms, System: 51.9 ms] Range (min … max): 220.0 ms … 455.8 ms 20 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Benchmark 2: cargo +stage1src check Time (mean ± σ): 256.6 ms ± 59.9 ms [User: 153.6 ms, System: 57.1 ms] Range (min … max): 233.8 ms … 508.2 ms 20 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Benchmark 3: cargo +stage1 build Time (mean ± σ): 273.9 ms ± 9.8 ms [User: 188.6 ms, System: 52.7 ms] Range (min … max): 258.2 ms … 288.3 ms 20 runs Benchmark 4: cargo +stage1src build Time (mean ± σ): 290.1 ms ± 12.3 ms [User: 197.6 ms, System: 60.5 ms] Range (min … max): 276.2 ms … 316.3 ms 20 runs Benchmark 5: cargo +stage1 build --release Time (mean ± σ): 234.3 ms ± 67.2 ms [User: 145.0 ms, System: 42.6 ms] Range (min … max): 208.5 ms … 517.8 ms 20 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Benchmark 6: cargo +stage1src build --release Time (mean ± σ): 238.4 ms ± 27.2 ms [User: 152.7 ms, System: 49.7 ms] Range (min … max): 222.3 ms … 350.3 ms 20 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. ``` So, 4%-5% for `build` and `check`, and really no difference for `build --release` (but we wouldn't expect one). ## Conclusion So, this is really unscientific. These aren't nearly enough iterations, I did it on a machine that was running other things (although I did quit most programs while running), and just generally it's not a good way to do it. I think it's pretty likely that it *does* represent a possible speedup of 3%-5%, since this was fairly consistent in the end. Additionally, my branch is really really hacky. I think almost none of it is the right way to go about this. So, in the list of steps given here <https://github.com/rust-lang/rust/pull/81782#issuecomment-784438001>, it's probably just the first one: "First probably measure the impact to see whether it's at all worth it.". So, is it worth it? Well, 3%-5% isn't exactly incredible, but it's also probably not worth giving up unless this is a total dead end. Thsis also *might* unblock using `#[global_allocator]` on Windows, which would be nice because we currently use the system allocator for everything there, AFAICT. One note is this undoes the reason we made this change in the first place. Basically, it forces everybody who depends on `rustc_driver` to use the same global allocator. This apparently was a problem for RLS back in <https://github.com/rust-lang/rust/pull/56986>, but with RLS on its way out, I'm unsure how much we care. (Also worth noting: this is also a much newer version of jemalloc which may not even have the issue that caused problems for RLS in the first place...). Who knows if we still care about this.

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully