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

WIP: Use sparse_list to save memory (see #1117) #1451

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

acdha
Copy link
Contributor

@acdha acdha commented Nov 9, 2016

The sparse list implementation avoids allocating the result cache elements
until something triggers loading the actual content.

This has a slight memory increase for very small querysets – roughly a custom
class + dict() vs. a list() – but the actual result data will usually be much
larger and the difference is cancelled out by the time the result cache is at a
thousand items.

This branch is currently broken using the released version of sparse_list – see
johnsyweb/python_sparse_list#5

@acdha acdha changed the title Use sparse_list to save memory (see #1117) WIP: Use sparse_list to save memory (see #1117) Nov 9, 2016
The sparse list implementation avoids allocating the result cache
elements until something triggers loading the actual content.

This has a slight memory increase for very small querysets – roughly a
custom class + dict() vs. a list() – but the actual result data will
usually be much larger and the difference is cancelled out by the time
the result cache is at a thousand items.

This branch is currently broken using the released version of
sparse_list – see johnsyweb/python_sparse_list#5
This bit of code really needs to be rewritten to avoid the loop but this
patch at least hits the point of being testable on Python 2
@@ -233,7 +234,7 @@ def _fill_cache(self, start, end, **kwargs):
# an array of 100,000 ``None``s consumed less than .5 Mb, which ought

Choose a reason for hiding this comment

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

I would change this comment here explaining that a sparse list is used because the total results set can be many orders of magnitude larger than the set of results that we pull at any given time.

Following a rapid upstream release, this should get the tests in django-haystack#1117 to pass against Python 3.
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

2 participants