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

perf: precompute intersections (2x speedup) #37

Merged
merged 2 commits into from
Oct 20, 2020
Merged

Conversation

Eh2406
Copy link
Member

@Eh2406 Eh2406 commented Oct 16, 2020

This is a cleaned up version of @mpizenberg's work in #33 (comment)

Copy link
Member

@mpizenberg mpizenberg left a comment

Choose a reason for hiding this comment

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

Looks good to me

@mpizenberg mpizenberg closed this Oct 17, 2020
@mpizenberg mpizenberg deleted the precompute_intersections branch October 17, 2020 21:51
@mpizenberg mpizenberg restored the precompute_intersections branch October 17, 2020 21:52
@mpizenberg
Copy link
Member

mpizenberg commented Oct 17, 2020

Woops sorry for closing this one. I was cleaning my unused branches and didn't realized the last commit was still mine here. I thought @Eh2406 would have done a new commit.

@mpizenberg mpizenberg reopened this Oct 17, 2020
@aleksator
Copy link
Member

I'll review in the morning.

@aleksator aleksator self-requested a review October 17, 2020 23:13
@@ -80,8 +80,7 @@ impl<P: Package, V: Version> PartialSolution<P, V> {
.rposition(|(l, _)| *l == decision_level)
.unwrap_or(self.history.len() - 1);
*self = Self::from_assignments(
self.history
.to_owned()
std::mem::take(&mut self.history)
Copy link
Member

Choose a reason for hiding this comment

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

This must be working as intended since tests pass, but I would like to ask for my own understanding.
std::mem::take replaces self.history with a default value, i.e. empty Vec in this case. Before the change the history was retained.

Why doing this is correct in this case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we are building a new self and its history and assigning it to *self.

old code:

let copy = self.history.to_owned();
let new_self = Self::from_assignments(copy);
*self = new_self;

Note how no one uses the self.history after the copy. It is just replaced as part of the last line.

Copy link
Member

Choose a reason for hiding this comment

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

Didn't see that, thank you for the explanation!

@mpizenberg
Copy link
Member

@aleksator why do we say term_intersection if we say "intersection of terms"? I'm really bad at grammar so I don't even know how to search for an explanation for that.

@aleksator
Copy link
Member

@aleksator why do we say term_intersection if we say "intersection of terms"? I'm really bad at grammar so I don't even know how to search for an explanation for that.

The rule of thumb in my understanding is yes. Let me try to google where I got that from... The search term I'm going to use is plural nouns as adjectives (I'm rather literal 😆).

First link from Duckduckgo is ambiguous, just saying that it can be either, but usually singular. It says plural is for nouns that usually refer to people or are mostly used in plural form; term is neither of those.

Second link defines a proper name for this which could be used for later searches: noun adjuncts, or attributive nouns.
It also gives a bunch of rules, but also ends with "whatever native speakers would use".

It is rather unhelpful 🙄, but that's what I generally use as a basis for my changes as well. If it sounds way off when I read it, it probably should be changed. If both ways sound clear or both sound a bit weird to my ear, then I leave it as is.

Disclaimer: I'm not a native speaker myself, although everything that could be done using English I do in English for the past decade or so. That only leaves verbal communication with surrounding people who don't speak English that has to be done in my native language, so I often find myself having to just drop in English words in my speech rather than pause trying to remember what the translation is. 😅

@aleksator aleksator merged commit 0f5c913 into dev Oct 20, 2020
@aleksator aleksator deleted the precompute_intersections branch October 20, 2020 13:32
@aleksator
Copy link
Member

An example of a function I didn't rename and why:
other_terms_intersection

Here if we rename it to other_term_intersection (without s) it would seem like we are trying to say another_(term_intersection) instead of intersection_of_(other_terms).

While intersection_of_other_terms reads smoother than other_terms_intersection, I thought that maybe it's better to keep the naming a) shorter and b) more consistent (we don't use of in other similar functions). Hence no changes this one.

@Eh2406
Copy link
Member Author

Eh2406 commented Oct 20, 2020

By the way, I am a native speaker, but my spelling and grammar are atrocious. So I deeply appreciate your correction of any mistakes you find.

@aleksator
Copy link
Member

By the way, I am a native speaker, but my spelling and grammar are atrocious. So I deeply appreciate your correction of any mistakes you find.

Thank you! I hope I'm not too pedantic with this stuff 😄

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.

3 participants