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

feat: Allow the UndoLog to be supplied separately #29

Merged
merged 18 commits into from
Apr 9, 2020

Conversation

Marwes
Copy link
Contributor

@Marwes Marwes commented Feb 26, 2020

From rust-lang/rust#69218 it was found that
keeping an individual undo log for each type that need snapshotting
incur noticeable overhead given how often snapshots are done and that
they are in many cases empty.

By separating the log like this, it is possible to store the undo log
and storage separately and only put the together when acting the the
underlying UnificationTable or SnapshotVec. In turn this allows multiple UnificationTables (and other types that can be snapshotted and reversed) to share a single undolog.

cc rust-lang/rust#69464

Markus Westerlind added 8 commits February 25, 2020 17:27
From rust-lang/rust#69218 it was found that
keeping an individual undo log for each type that need snapshotting
incur noticeable overhead given how often snapshots are done and that
they are in many cases empty.

By separating the log like this, it is possible to store the undo log
and storage separately and only put the together when acting the the
underlying `UnificationTable` or `SnapshotVec`
@Marwes Marwes changed the title feat: Allow the UndoLog to supplied separately feat: Allow the UndoLog to be supplied separately Feb 26, 2020
@nikomatsakis nikomatsakis self-assigned this Mar 3, 2020
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Ok, I did a first read. I am starting to understand what this PR is actually doing. =)

@Marwes is there any kind of write-up explaining the way this stuff is meant to be used?

ena is not really a very clearly encapsulated library, I forget if we have much in the way of docs -- if we did, I'd say you should definitely add to them. :P

src/unify/mod.rs Outdated Show resolved Hide resolved
@Marwes
Copy link
Contributor Author

Marwes commented Mar 20, 2020

is there any kind of write-up explaining the way this stuff is meant to be used?

Added a test showing a simple version, otherwise there is just rust-lang/rust#69464

@Marwes
Copy link
Contributor Author

Marwes commented Mar 27, 2020

@nikomatsakis Anything else I can do to move this forward?

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

Hi @Marwes -- sorry, it's been hard to carve out time, but I did a first pass over this change. I've asked for a lot of doc comments and the like, in part to make up for older code that should've been documented, but also to try and understand what the role is of each trait and so forth (to some extent, I'm "playing dumb" a bit here -- i.e., it's been a while since I looked at this code, so I have the advantage of being really confused and thus able to see better how much stuff is being assumed and not stated explicitly or commented).

src/undo_log.rs Outdated Show resolved Hide resolved
src/undo_log.rs Outdated Show resolved Hide resolved
src/unify/mod.rs Outdated
@@ -176,14 +180,21 @@ pub struct VarValue<K: UnifyKey> { // FIXME pub
/// - This implies that ordinary operations are quite a bit slower though.
/// - Requires the `persistent` feature be selected in your Cargo.toml file.
#[derive(Clone, Debug, Default)]
pub struct UnificationTable<S: UnificationStore> {
pub struct UnificationTable<S> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to remove the bound here?

src/unify/mod.rs Outdated
K: UnifyKey,
V: sv::VecLike<Delegate<K>>,
{
pub fn with_log<'a, L2>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you document how this method is meant to be used and what it does?

It seems a bit surprising to me since ordinarily I think of there being "just one" undo-log for a given table.

I guess the idea here is that, since snapshots are "stacked", you can "push a new log" on and you'll fully work through the snapshots that are in that new log before you come back to whatever log was there before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to only be implemented on the Storage types which has () in place of the undo log. Since () does not implement UndoLogs mutating methods can't be called. with_log creates an actual UnificationTable which can then be mutated.

src/unify/tests.rs Outdated Show resolved Hide resolved
src/undo_log.rs Show resolved Hide resolved
src/undo_log.rs Show resolved Hide resolved
src/undo_log.rs Show resolved Hide resolved
src/undo_log.rs Outdated
fn actions_since_snapshot(&self, snapshot: &Self::Snapshot) -> &[T];

fn start_snapshot(&mut self) -> Self::Snapshot;
fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rollback (undo) the changes made since the snapshot back.

Question:

What is values here?

src/undo_log.rs Outdated
}
}

/// A trait implemented for types which can be rolled back using actions of type `U`.
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be great to give an example of what is meant to implement Rollback -- I think it's the values in the table? Not sure

@nikomatsakis
Copy link
Contributor

@Marwes I'll try to stay on top of this from now on! I want to see it land. Apologies for the delay.

@nikomatsakis
Copy link
Contributor

Read through the latest changes. I'm going to merge this, thanks!

@nikomatsakis nikomatsakis merged commit 5a500c4 into rust-lang:master Apr 9, 2020
@Marwes Marwes deleted the detach_undo_log branch April 10, 2020 06:41
@Marwes
Copy link
Contributor Author

Marwes commented Apr 10, 2020

@nikomatsakis Will update rust-lang/rust#69464 once a release of ena is done!

nikomatsakis added a commit to nikomatsakis/ena that referenced this pull request Apr 10, 2020
Changes:

* Allow the UndoLog to be supplied separately (rust-lang#29)
@nikomatsakis nikomatsakis mentioned this pull request Apr 10, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2020
perf: Unify the undo log of all snapshot types

Extracted from rust-lang#69218 and extended to all the current snapshot types.

Since snapshotting is such a frequent action in the compiler and many of the scopes execute so little work, the act of creating the snapshot and rolling back empty/small snapshots end up showing in perf. By unifying all the logs into one the creation of snapshots becomes significantly cheaper at the cost of some complexity when combining the log with the specific data structures that are being mutated.

Depends on rust-lang/ena#29
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