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

Cache manifest everywhere #14537

Merged
merged 2 commits into from
Dec 20, 2018
Merged

Cache manifest everywhere #14537

merged 2 commits into from
Dec 20, 2018

Conversation

Hexcles
Copy link
Member

@Hexcles Hexcles commented Dec 14, 2018

Move the cache layer of manifest objects from wpt.testfiles to
manifest.manifest so that all users of the manifest module can benefit.

This prevents us from having two in-memory copies of the manifest when
running affected tests (one loaded by wpt.testfiles and the other loaded
by wptrunner.testloader). Partly fixes #14421 (the memory usage part of
it, but not the code health part).


load_manifest = _init_manifest_cache()
def load_manifest(manifest_path=None, manifest_update=True):
from manifest import manifest
Copy link
Member Author

Choose a reason for hiding this comment

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

Switch to a delayed import here because otherwise Python will think there are two different manifest modules (because of different import paths) and we don't get the singleton.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you say we document your rationale with a comment? I'm afraid of your
optimization being accidentally subverted by some future refactoring (the
corresponding performance degradation might not be noticed immediately).

This is beyond my experience with Python, though. Can you advise on any
longer-term goals that would obviate this kind of consideration?

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 added a comment here, but I don't really have great ideas how to make sure we always get a singleton.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you verify that the previous code was broken? I know that foo.bar and bar are different even if they're the same bar.py file, but I'm slightly surprised if that also affects relative imports.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I did. It took me a while to realize what was going on.

@Hexcles
Copy link
Member Author

Hexcles commented Dec 14, 2018

On my machine, this reduces 2GB of memory usage (peak memory 5GB -> 3GB) when running

./wpt run --affected HEAD^1 --log-mach - --binary ~/tools/firefox-nightly/firefox firefox

(with a dummy local commit)

tools/manifest/manifest.py Outdated Show resolved Hide resolved
tools/manifest/manifest.py Outdated Show resolved Hide resolved
@Hexcles
Copy link
Member Author

Hexcles commented Dec 18, 2018

I addressed the review comments, but am having trouble debugging the tools/wpt failure on macOS -- I can't reproduce the error locally on my Macbook.

I'll try to dig deeper.

@Hexcles
Copy link
Member Author

Hexcles commented Dec 19, 2018

So my working theory is that test_wpt.py had a module-level fixture to create a temporary manifest, which means the manifest path was the same for all test cases, but some test cases need to modify the manifest, so caching by path failed. The workaround is to use a different temporary manifest for each test case (and the temporary manifest is copied from a "persistent" one, which is initialized in a module-level setup function to avoid having to generate the manifest every time). See my second commit. This seems to work. However, I don't really understand why the problem only demonstrated on macOS.

@jgraham PTAL again.

@foolip
Copy link
Member

foolip commented Dec 19, 2018

FYI, I've rebased this branch to trigger "Travis CI - Pull Request", manually setting things right after the travis-ci.com transition in #14499 changed the name of the required check, which applies retroactively.

Move the cache layer of manifest objects from wpt.testfiles to
manifest.manifest so that all users of the manifest module can benefit.

This prevents us from having two in-memory copies of the manifest when
running affected tests (one loaded by wpt.testfiles and the other loaded
by wptrunner.testloader). Partly fixes #14421 (the memory usage part of
it, but not the code health part).
The test module uses the same temporary manifest in all test cases, but
some test cases modify the manifest, which causes inconsistency in the
cache. This commit changes the test setup to initialize a persistent
manifest on the module level, and each test case will then make a
temporary copy of it.

Also speed up tools/wpt tests on Azure by updating the manifest first.
@Hexcles Hexcles merged commit 5d72055 into master Dec 20, 2018
@Hexcles Hexcles deleted the cache-manifest branch December 20, 2018 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make it possible to thread the manifest through the code when it's used multiple times
5 participants