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

order layers by MRO before doing topological sort #14

Merged
merged 3 commits into from Dec 26, 2014

Conversation

davisagli
Copy link
Member

Currently the test runner sorts layers by name and then does a topological sort to make sure that a layer runs after the layers it depends on. This is suboptimal if there are many layers that share ancestry; it doesn't do anything to make sure those layers run consecutively, so we end up setting up and tearing down layers more than necessary.

This changes order_by_bases to do an initial sort by reversed MRO instead of by name so that layers with shared ancestry end up adjacent. This appears to speed up Plone's tests by about 30%.

I haven't run the zope.testrunner tests yet with this change, so let's see what travis says...

def layer_sortkey(layer):
return tuple((c.__module__, c.__name__) for c in getmro(layer)[::-1] if c is not object)

layers = [layer for layer in layers]
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be better spelled layers = list(layers).

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that first, but the function is called with a dict in one case (in which case we want the keys) and a list in other cases.

Copy link
Member

Choose a reason for hiding this comment

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

list() on a dict gives you a list of the dict's keys.

@mgedmin
Copy link
Member

mgedmin commented Nov 5, 2014

A 30% test speedup sounds like a worthwhile goal!

I'm worried about merging this without tests for the new behavior. Now I know zope.testrunner's tests are very painful (it's why I stopped contributing to zope.testrunner myself), but would you please try?

@davisagli
Copy link
Member Author

Sure, I'll try to add a test in the next day or two.

@mgedmin
Copy link
Member

mgedmin commented Nov 5, 2014

I noticed in one of your previous rebases that you had a side effect that made the unit test layer run first. I got very excited about that (see bug #497871 in the old tracker) before noticing the final diff.

Oh well, perhaps we can reuse the test changes from c8282f2 in a separate PR.

@davisagli
Copy link
Member Author

I was excited about that too. Might take another look. And looks like that bug has some unit tests which I can adapt.

@do3cc
Copy link
Member

do3cc commented Dec 23, 2014

I've created a different PR with unittests first. basically by modifying this PR

@mgedmin mgedmin mentioned this pull request Dec 23, 2014
@do3cc do3cc merged commit 37a1408 into master Dec 26, 2014
@tseaver tseaver deleted the davisagli-layer-ordering branch March 17, 2015 13:26
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.

None yet

3 participants