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

Reduce memory usage by using global Arc-based interning #8284

Merged
merged 5 commits into from
Apr 2, 2021
Merged

Reduce memory usage by using global Arc-based interning #8284

merged 5 commits into from
Apr 2, 2021

Conversation

jonas-schievink
Copy link
Contributor

This saves around 50 mb when running analysis-stats on r-a itself. Not a lot, but this infra can be easily reused to intern more stuff.

@jonas-schievink
Copy link
Contributor Author

Added interning of more types. Memory impact looks roughly like this:

in crates/rust-analyzer, run
$ cargo run --features jemalloc --release --bin rust-analyzer -- -v analysis-stats ../.. --parallel --memory-usage

base (master)

Total:               14.66s, 81ginstr, 1196mb
   182mb FileItemTreeQuery
    79mb BodyQuery


intern TypeRef+TraitRef

Total:               14.45s, 81ginstr, 1143mb
   144mb FileItemTreeQuery
    79mb BodyQuery


intern ModPath in Attr

Total:               14.72s, 81ginstr, 1117mb
   128mb FileItemTreeQuery
    79mb BodyQuery


also intern ModPath in item_tree::MacroCall

Total:               14.10s, 81ginstr, 1110mb
   119mb FileItemTreeQuery
    79mb BodyQuery


intern ModPath in Path

Total:               14.09s, 81ginstr, 1073mb
   105mb FileItemTreeQuery
    70mb TraitSolveQuery (purge)
    66mb ImplDatumQuery
    65mb BodyQuery

@jonas-schievink jonas-schievink changed the title Global TypeRef/TraitRef interning Reduce memory usage by using global Arc-based interning Apr 1, 2021
@flodiebold
Copy link
Member

Nice, we should try that for types as well!

@jonas-schievink
Copy link
Contributor Author

bors r+

bors bot added a commit that referenced this pull request Apr 1, 2021
8284: Reduce memory usage by using global `Arc`-based interning r=jonas-schievink a=jonas-schievink

This saves around 50 mb when running `analysis-stats` on r-a itself. Not a lot, but this infra can be easily reused to intern more stuff.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
@bors
Copy link
Contributor

bors bot commented Apr 1, 2021

Timed out.

@jonas-schievink
Copy link
Contributor Author

warning: spurious network error (10 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates.io)

bors retry

bors bot added a commit that referenced this pull request Apr 1, 2021
8284: Reduce memory usage by using global `Arc`-based interning r=jonas-schievink a=jonas-schievink

This saves around 50 mb when running `analysis-stats` on r-a itself. Not a lot, but this infra can be easily reused to intern more stuff.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
@bors
Copy link
Contributor

bors bot commented Apr 1, 2021

Build failed:

@matklad
Copy link
Member

matklad commented Apr 2, 2021

I wonder if we might want do something like this, but without interning, for basically everything?

I still have a picture in my head where all things of the same type are co-allocated in the same table, instead of being owned by parents.

@jonas-schievink
Copy link
Contributor Author

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 2, 2021

@bors bors bot merged commit f4d5698 into rust-lang:master Apr 2, 2021
@jonas-schievink jonas-schievink deleted the global-intern branch April 2, 2021 16:51
@lnicola
Copy link
Member

lnicola commented Apr 2, 2021

changelog fix

@lnicola
Copy link
Member

lnicola commented Apr 2, 2021

This put quite a dent in the memory usage:

image

image

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

Successfully merging this pull request may close these issues.

4 participants