8000 Simplify and optimize `ItemTree` by Veykril · Pull Request #19982 · rust-lang/rust-analyzer · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simplify and optimize ItemTree #19982

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

Merged
merged 14 commits into from
Jun 13, 2025
Merged

Conversation

Veykril
Copy link
Member
@Veykril Veykril commented Jun 12, 2025

Follow up to #19837, closes #9023

There is a bunch of things in the item tree we can replace now as item tree ids are superfluous, we can just replace them with an ast id mapping.

@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from e16bf7b to 1780e48 Compare June 12, 2025 08:25
@ChayimFriedman2
Copy link
Contributor

FWIW, I thought about collapsing all item tree arenas into one, and using an enum in the contents, to reduce memory usage. #19837 was a requirement to that because otherwise it would have hurt incrementality.

@Veykril
Copy link
Member Author
Veykril commented Jun 12, 2025

Ye figured, your PR is totally a requirement for all the changes here. Sorry if I was stealing planned follow up work from you, I just noticed this and couldn't resist :)

@ChayimFriedman2
Copy link
Contributor

No this is fine :)

@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from 1780e48 to 8930c58 Compare June 12, 2025 09:22
@Veykril
Copy link
Member Author
Veykril commented Jun 12, 2025

Neat this undoes the memory regression

@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from 2c8f597 to 87083eb Compare June 12, 2025 10:11
@Veykril Veykril marked this pull request as ready for review June 12, 2025 10:13
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 12, 2025
@Veykril Veykril changed the title [Wip]: Simplify ItemTree Simplify and optimize ItemTree Jun 12, 2025
@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from 87083eb to 93da36a Compare June 12, 2025 10:31
@Veykril Veykril requested a review from ChayimFriedman2 June 12, 2025 10:50
@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from e18080b to c1d7c53 Compare June 12, 2025 10:52
attrs: FxHashMap<FileAstId<ast::Item>, RawAttrs>,
vis: ItemVisibilities,
// FIXME: They values store the key, turn this into a FxHashSet<ModItem> instead?
data: FxHashMap<FileAstId<ast::Item>, ModItem>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need a hashmap? I think we can just store an arena, and the ModItemId will be the Idx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModItemId is a typed enum around FileAstId now. Introducing an arena will give us effectively back what FileItemTreeId was

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what is the advantage of having a wrapper around FileAstId? The advantage of an arena is that it saves more memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, if we add back the sequential indices than item re-shuffling will invalidate things here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalidate what? Nobody depends on the item tree anymore except for the def map, and it'll be invalidated anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I prefer the current setup as its a lot simpler given we have one less layer of IDs to handle.

The advantage of an arena is that it saves more memory.

I am also not so sure about this, if we turn this into an IndexSet and use the keys of the values contained themselves I do not believe there to be a big memory difference at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually we can drop the ast id field from the mod items entirely, you only have access to it if you have they key, which is the ast id already

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having worked on the more recent commits I am confident that adding another ID layer won't be helpful for us. I highly doubt it will have a observable memory impact and it would also require adding back a resolution indirection to go from that ID back to the AstId while also adding back a good chunk of code I was able to cut entirely.

Copy link
Contributor
@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall a good idea, but there are some things I prefer to see changed.

@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from c1d7c53 to d8a6aae Compare June 12, 2025 11:35
@davidbarsky
Copy link
Contributor

I can run this myself shortly, but does this have an impact on cache priming?

@Veykril
Copy link
Member Author
Veykril commented Jun 12, 2025

Shouldn't. I meant optimize as far as memory is concerned fwiw, I don't think this will have a execution time impact

@ChayimFriedman2
Copy link
Contributor
ChayimFriedman2 commented Jun 12, 2025

@davidbarsky

I can run this myself shortly, but does this have an impact on cache priming?

#19837 could have an effect on cache priming, due to less things in the item tree! You can try and see.

@Veykril
Copy link
Member Author
Veykril commented Jun 13, 2025

65e2e2c saved another 9mb

@Veykril
Copy link
Member Author
Veykril commented Jun 13, 2025

63fb37b (#19982) is another 4

@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from 63fb37b to 9b78c1f Compare June 13, 2025 07:05
@Veykril Veykril requested a review from ChayimFriedman2 June 13, 2025 07:08
@Veykril Veykril force-pushed the push-uptnmqtlylsx branch from 9b78c1f to 16ebd29 Compare June 13, 2025 11:05
@Veykril Veykril enabled auto-merge June 13, 2025 11:06
@Veykril Veykril added this pull request to the merge queue Jun 13, 2025
Merged via the queue into rust-lang:master with commit bd002fe Jun 13, 2025
14 checks passed
@Veykril Veykril deleted the push-uptnmqtlylsx branch June 13, 2025 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flat storage for ItemTrees
4 participants
0