Skip to main content

Implementations for the various Python Collection ABCs that optimize along various axes.

Project description

Opticol

Optimized collections (hence opticol) for Python. This package provides memory optimized versions of the base Python collection types which are:

  • (Mutable)Sequence
  • (Mutable)Mapping
  • (Mutable)Set

The insight behind the package is the following: the size of an empty set is 216 bytes (on Python 3.14) but the size of an empty object with an empty slots member is only 32 bytes. Python programs that hold large datasets in memory could benefit from using these optimized collections which fully implement the respective collection ABCs, but at a fraction of the runtime memory.

So for general users these optimizations will not be worth if if the dataset being used comfortably fits in memory, but applications which currently create tens or hundreds of thousand of Python objects could dramatically lower memory usage without API changes.

Usage

The optimized classes could be used directly, by creating an EmptySequence directly for example, but the recommended usage is to use the collection level project method which tries to project a collection instance into the memory optimized variants automatically. Additionally, there is a factory interface that could be plugged in to allow for different strategies beyond the typical project logic.

Consider the following example:

import opticol

optimized_list = opticol.seq_project([]) # Actually an instance of EmptySequence
optimized_list_single = opticol.mut_seq_project(("MyString",)) # Actually an instance of Small1MutableSequence

A small note that in the current implementation, optimization is only in one direction. That is, if the MutableSequence type is optimized for collections of size 0, 1, 2, 3, then once an operation pushes it past into size 4, further decreasing of the size will not restore the optimization.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opticol-0.1.0a1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opticol-0.1.0a1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file opticol-0.1.0a1.tar.gz.

File metadata

  • Download URL: opticol-0.1.0a1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opticol-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 0f389f03d87a0c2b46869c130f1717b9ac7337ad6edea862617dde97c5d02bfd
MD5 6294181b710a44882f375e85f269bd65
BLAKE2b-256 5735e405a9ea6cca70d4c58660d78006d1681162b8abbdf1184d0f22ac3e48df

See more details on using hashes here.

File details

Details for the file opticol-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: opticol-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for opticol-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 90025f83cef5c9c36625c855cc4b49b11cb936cce1aa7c62c51ab180a74d036e
MD5 54cf1a1872223b7a2e79b6c552d0fbf1
BLAKE2b-256 0cba22ad1bdcbc48fcf0a264ae365dec0c3622c532ae4118d1f918e71e661a28

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page