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

Implement a sqlite-based store for the cache #6023

Merged
merged 6 commits into from
Dec 10, 2018
Merged

Implement a sqlite-based store for the cache #6023

merged 6 commits into from
Dec 10, 2018

Conversation

msullivan
Copy link
Collaborator

File system operations on OS X are pretty slow, and untarring a large
archive of mypy cache information can get pretty slow. Work around
this by using a sqlite database to store the entire cache in one file.

To do this we introduce a generic interface for storing metadata,
called MetadataStore. It presents an essentially key/value
interface. We provide two implementations, one using the existing file
system backing and one using sqlite.

It is enabled with the option --sqlite-cache, but is not the default
yet.

I'm not sure what the right thing to do about testing is. I've tested
it with the default changed, and everything passes.

File system operations on OS X are pretty slow, and untarring a large
archive of mypy cache information can get pretty slow. Work around
this by using a sqlite database to store the entire cache in one file.

To do this we introduce a generic interface for storing metadata,
called `MetadataStore`. It presents an essentially key/value
interface. We provide two implementations, one using the existing file
system backing and one using sqlite.

It is enabled with the option `--sqlite-cache`, but is not the default
yet.

I'm not sure what the right thing to do about testing is. I've tested
it with the default changed, and everything passes.
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks! This looks very good, I just have some documentation suggestions.

misc/convert-cache.py Outdated Show resolved Hide resolved

for s in input.list_all():
# print("Copying", s)
assert output.write(s, input.read(s), input.getmtime(s))
Copy link
Member

Choose a reason for hiding this comment

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

I would give a reasonable error message if this fails. Also, do we need to perform a cleanup for partially written cache to disk in this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's just a debugging script, so I dunno if it matters?

Copy link
Member

Choose a reason for hiding this comment

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

Up to you, but if we expect that someone except us will use it (I assume), then think it is better to do it.

misc/convert-cache.py Outdated Show resolved Hide resolved
structure of files.
* A hokey sqlite backed implementation, which basically simulates
the file system in an effort to work around poor file system performance
on OS X.
Copy link
Member

Choose a reason for hiding this comment

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

What about Windows? Is it also fast or also slow?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have no idea at all

mypy/metastore.py Show resolved Hide resolved
mypy/metastore.py Show resolved Hide resolved
mypy/metastore.py Outdated Show resolved Hide resolved

class SqliteMetadataStore(MetadataStore):
def __init__(self, cache_dir_prefix: str) -> None:
if cache_dir_prefix.startswith('/dev/null'):
Copy link
Member

Choose a reason for hiding this comment

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

Why startswith and not ==? I would also documment this behavior in a docstring.

mypy/metastore.py Show resolved Hide resolved
misc/convert-cache.py Show resolved Hide resolved
mypy/build.py Outdated Show resolved Hide resolved
mypy/build.py Show resolved Hide resolved
mypy/build.py Show resolved Hide resolved
mypy/metastore.py Outdated Show resolved Hide resolved
mypy/metastore.py Outdated Show resolved Hide resolved
mypy/metastore.py Outdated Show resolved Hide resolved
mypy/metastore.py Outdated Show resolved Hide resolved
mypy/metastore.py Show resolved Hide resolved
mypy/metastore.py Show resolved Hide resolved
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

LGTM now.

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.

4 participants