Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Conversation

@bnjbvr
Copy link
Member

@bnjbvr bnjbvr commented Jun 1, 2020

This series of commits reduce the number of memory allocations during compilation with Cranelift:

  • first commit uses the default implementation of Clone for Set, which is more efficient (as it avoids reallocations) and has the same effect.
  • second commit reduces the number of allocations in get_range_frags, by: flushing RangeFrag as they're created instead of accumulating them in a Vec flushed at the end; reusing memory across block iterations. Some of this work might be undone by Julian's future patches, but it's a direct improvement here.
  • The last commit (breaking change) requires that add_uses/add_defs are given Slices of Reg/WritableReg instead of Sets, which reduces the number of memory allocations, when combined with a symmetrical patch in Cranelift.

Each commit has been tested for performance separately and did improve all the metrics (icount, number of malloc'd bytes and blocks), when tested on joey-big/joey-medium/regex-rs.wasm test cases. For the latter, it's a 9% icount decrease, 19% block allocations decrease, 10% total of allocated bytes decrease.

bnjbvr added 3 commits June 1, 2020 18:59
The manual implementation of clone was not efficient, since it would
cause a lot of resizes of the underlying set structure. There's already
an efficient Clone implementation for FxHashSet, so use that instead.
This removes the need for one vector entirely by flushing range fragment
creation when they're ready, instead of waiting up to the end. It also
reuses a Map across block iterations, instead of creating one that's
resized over time.
…s as inputs;

The data-flow analysis ensures later on that there are no duplicates in
these lists, so the user doesn't have to worry about this, and thus can
pass plain slices for all of these.
@bnjbvr bnjbvr force-pushed the memory-enhancements branch from e38eb03 to 793bd1a Compare June 1, 2020 17:00
Copy link
Contributor

@julian-seward1 julian-seward1 left a comment

Choose a reason for hiding this comment

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

LGTM.

// Sets of things

// Same comment as above for FxHashMap.
#[derive(Clone)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Umm, yes. Now I wonder why I didn't do this to begin with :-)

@bnjbvr bnjbvr merged commit bb95a95 into bytecodealliance:master Jun 2, 2020
@bnjbvr bnjbvr deleted the memory-enhancements branch June 2, 2020 13:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants