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

Improve memory characteristics of ExportsMap #3231

Merged
merged 4 commits into from
Dec 20, 2022
Merged

Conversation

wz1000
Copy link
Collaborator

@wz1000 wz1000 commented Sep 28, 2022

Storing rendered names as Text, especially for parents, adds a lot of duplication to the ExportsMap.
Instead we store the OccNames directly, which have hash-consed symbols due stored as FastStrings
and render it out on demand (which is just decoding the UTF-8 FastString to UTF-16 text for text <2.0,
and essentially free on text >2.0).

This PR depends on #3204, ignore that commit while reviewing.

mText = pack $ moduleNameString mn
fmap (wrap . unwrap mText) <$> withHieDb (\hieDb -> getExportsForModule hieDb mn)
let exportsMap = Map.fromListWith (<>) (concat idents)
return $ ExportsMap exportsMap $ buildModuleExportMap (concat idents)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This fixes a bug where the module exports map created from hiedb would be keyed by the identifier name instead of the module name. Caught because of using proper types instead of Text!

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

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

This looks good to me, but could you share some benchmarks showing the improvement?

@wz1000 wz1000 force-pushed the wip/exports-map-mem branch from 6a6493c to a4fe2bf Compare December 12, 2022 11:32
@wz1000 wz1000 requested a review from santiweight as a code owner December 12, 2022 11:32
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch 4 times, most recently from e5cb905 to c13ef89 Compare December 14, 2022 10:00
@wz1000 wz1000 requested a review from isovector as a code owner December 14, 2022 10:00
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch 4 times, most recently from 4044636 to 7e64746 Compare December 18, 2022 21:40
@wz1000 wz1000 requested a review from July541 as a code owner December 18, 2022 21:40
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch 2 times, most recently from c9c3181 to b7896be Compare December 19, 2022 11:28
@wz1000 wz1000 enabled auto-merge (rebase) December 19, 2022 11:31
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch from b7896be to 4ca97e2 Compare December 19, 2022 12:08
Storing rendered names as `Text`, especially for parents, adds a lot of duplication to the ExportsMap.
Instead we store the `OccName`s directly, which have hash-consed symbols due stored as `FastStrings`
and render it out on demand (which is just decoding the UTF-8 FastString to UTF-16 text for text <2.0,
and essentially free on text >2.0).
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch from 4ca97e2 to 996c62a Compare December 20, 2022 09:16
@wz1000 wz1000 force-pushed the wip/exports-map-mem branch from 996c62a to 7a4e1a9 Compare December 20, 2022 09:40
@wz1000 wz1000 merged commit f94385e into master Dec 20, 2022
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.

2 participants