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

depgraph: make _minimize_children deterministic (bug 631894) #209

Merged
merged 1 commit into from Sep 25, 2017

Conversation

zmedico
Copy link
Member

@zmedico zmedico commented Sep 24, 2017

In order for the eliminate_pkg loop to produce deterministic results,
the order of the pkgs list must not be random. Prefer to eliminate
installed packages first, in case rebuilds are needed, and also sort
in ascending order so that older versions are eliminated first.

X-Gentoo-bug: 631894
X-Gentoo-bug-url: https://bugs.gentoo.org/631894

@danielrobbins

# packages first, in case rebuilds are needed, and also sort
# in ascending order so that older versions are eliminated
# first.
pkgs = (sorted(pkg for pkg in pkgs if pkg.installed) +
Copy link
Contributor

Choose a reason for hiding this comment

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

How big is the list going to be? Maybe it makes sense to bisect.insort here and not touch every element twice.

installed = []
not_installed = []
for pkg in pkgs:
  if pkg.installed:
    bisect.insort(installed, pkg)
  else:
    bisect.insort(not_installed,pkg)

pkgs = installed + not_installed

Copy link
Member Author

Choose a reason for hiding this comment

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

Typically we're only dealing with 2 packages, so there's not much cost here to optimize away. Also, insort would be less efficient than something like this:

installed = []
not_installed = []
for pkg in sorted(pkgs):
   if pkg.installed:
     installed.append(pkg)
   else:
     not_installed.append(pkg)

And that's going to have a negligible performance difference compared to my 2-line version that's easier to read.

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, if it's just a small list then nevermind my comment 👍

In order for the eliminate_pkg loop to produce deterministic results,
the order of the pkgs list must not be random. Prefer to eliminate
installed packages first, in case rebuilds are needed, and also sort
in ascending order so that older versions are eliminated first.

X-Gentoo-bug: 631894
X-Gentoo-bug-url: https://bugs.gentoo.org/631894
Reviewed-by: Manuel Rüger <mrueg@gentoo.org>
@gentoo-bot gentoo-bot merged commit 5b286b2 into gentoo:master Sep 25, 2017
@zmedico zmedico deleted the bug_631894 branch October 13, 2017 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants