Skip to content

Document the memory cost of reading PropertyBitmaps.bitmaps - #213

Open
ulfarsson wants to merge 2 commits into
developfrom
bitmaps-memory-note
Open

ulfarsson wants to merge 2 commits into
developfrom
bitmaps-memory-note

Conversation

@ulfarsson

Copy link
Copy Markdown
Member

Reading a length from PropertyBitmaps.bitmaps can build that length's whole bitmap. That happens when the length is kept as the indices of its few good permutations. This adds a paragraph and an example to PropertyBitmaps' docstring (permuta/bisc/bisc.py), saying which reads build bitmaps and which do not. No code changes. The example: one good permutation of length 8 is kept as an index, and is read back as a bitmap of 5,040 bytes:

>>> pb = PropertyBitmaps(Perm.is_increasing)
>>> pb.add_length(8)
>>> pb.good_counts[8], len(pb.bitmaps[8])
(1, 5040)

At length 14 the same read costs 10.9 GB. So if pb.bitmaps holds length 14 as indices:

  • 14 in pb.bitmaps, list(pb.bitmaps) and len(pb.bitmaps) build nothing;
  • dict(pb.bitmaps), pb.bitmaps.items(), pb.bitmaps.values(), or PropertyBitmaps(bitmaps=pb.bitmaps) build the bitmap of length 14: 10.9 GB.

This matters to anyone who keeps a PropertyBitmaps' labels between runs of bisc or auto_bisc. The class docstring suggests doing that, and bitmaps is the natural way to read them out.

Details

  • The paragraph comes after the one on the attributes, in the class docstring's style, and the example ends the doctests, as bitmaps had none.
  • Its source: Add PropertyBitmaps: bisc and auto_bisc keep their input as bitmaps, or as indices where few are good #209's docstring had the same note until its last commit shortened it. No other docstring says it now.
  • Its claims are the code's:
    • _Bitmaps.__getitem__ builds the bitmap of a length kept as indices each time it is asked for one.
    • _Bitmaps.__contains__ is overridden, so that in builds nothing.
    • _LengthKeys.__iter__ and __len__ read only the lengths.
    • The constructor reads a given bitmaps through items().
  • Checked by counting the builds of each way of reading bitmaps, on a PropertyBitmaps of Perm.is_increasing with lengths 5 to 8 kept as indices:
    • in, list() and len() make none;
    • items(), values(), dict() and the constructor make one for each such length;
    • the constructor keeps those lengths as indices again.
  • The size: 10.9 GB is the module's own size for length 14, (14! + 7) // 8 = 10,897,286,400 bytes.
  • Tests: tox's flake8, mypy, pylint and black pass. All 696 tests pass on CPython 3.15, and 694 on PyPy 3.12, with the 2 reference-count and tracemalloc tests skipped there, bisc.py's doctests among them. Tilings' 3,722 tests pass at its develop with this Permuta, on both Pythons.
  • No CHANGELOG entry: Unreleased already names PropertyBitmaps.

AI assistance: written with Claude Code (Opus 5.5) as the Permuta developer, and reviewed before submission by Claude Code (Opus 5.5) as an automated reviewer; Henning Ulfarsson checked and opened it.

ulfarsson and others added 2 commits November 6, 2026 16:58
PropertyBitmaps.bitmaps builds the bitmap of a length kept as the
indices of its good permutations each time it is asked for it, so
items(), values() and dict(bitmaps), or bitmaps given to another
PropertyBitmaps, build every such length's bitmap: 10.9 GB for length
14. Asking whether a length is there, iterating over the lengths and
len() build none. The class docstring said so until the last commit of
#209 shortened it, and no other docstring says it now. This puts the
note back, in the shortened docstring's style.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bitmaps had no example among the class's doctests. This one reads a
length kept as the index of its one good permutation through bitmaps,
which builds its whole bitmap, 5,040 bytes at length 8: the cost the
paragraph above the examples describes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant