A library that uses OS-level userfaulting to lazily download chunks of remote data (e.g., from S3) as they are accessed, enabling fast probing of large arrays without full download.

Stars

26

7-day growth

No data

Forks

0

Open issues

0

License

AGPL-3.0

Last updated

2026-07-06

AI repository intelligence
FR-AI / ANALYSIS

Why it is worth attention

Leverages the underutilized userfaulting API to achieve extremely fast lazy loading of remote data, downloading only needed blocks.

Who it is for

  • Data scientists working with large remote arrays
  • Engineers needing efficient remote data access
  • Rust/Python developers interested in OS-level memory management techniques
  • Researchers analyzing huge datasets on cloud storage

Use cases

  • Lazy loading of NumPy arrays from S3 for quick exploration
  • Efficiently probing large remote datasets without downloading the entire file
  • Memory-mapping remote files for random access with minimal latency

Strengths

  • Lightning fast probing – demo loads two 400MB+ arrays in ~100ms
  • Persistent LRU cache makes repeated runs as fast as local
  • Leverages userfaulting for transparent lazy loading
  • Python and Rust APIs for flexibility

Considerations

  • Only supports macOS currently
  • Very rough and not production-ready according to authors
  • Requires Rust development environment (maturin) to build
  • Limited error handling and no support for Windows/Linux yet

README quick start

DEMAND MAP

How many times have you been forced to download a big file from S3? There's a criminally underutilised API on modern systems that allows you to index arrays and attach callbacks if the data isn't there, called userfaulting. Unfortunately, barely anyone knows about this and the API differs on Windows, Linux, and macOS, respectively increasing in just how esoteric the API is.

This allows you to lazily download chunks of data, as you read the underlying array, while caching blocks to your file system. This makes it LIGHTNING fast for probing data remotely as you only download what you need.

Running the Demo

pip install polars numpy maturin
maturin develop
python demo.py
alloc = demandmap.S3Alloc(
    "./cache.bin",
    # number of blocks
    capacity=512,
    # one megabyte block (per request chunk size)
    block_size=1048576
)

buf1 = alloc.get("https://rollo-testing.lon1.digitaloceanspaces.com/big_col.npz.npy")
buf2 = alloc.get("https://rollo-testing.lon1.digitaloceanspaces.com/big_col2.npz.npy")

# Both over 400mb
assert buf1.nbytes > 400000000
assert buf2.nbytes > 400000000

# But this takes ~100ms
df = pl.DataFrame([
    ndarray_from_npy_buffer(buf1),
    ndarray_from_npy_buffer(buf2)
])
# shape: (50_000_000, 2)
# ┌──────────┬──────────┐
# │ column_0 ┆ column_1 │
# │ ---      ┆ ---      │
# │ i64      ┆ i64      │
# ╞══════════╪══════════╡
# │ 0        ┆ 1000     │
# │ 1        ┆ 1001     │
# │ 2        ┆ 1002     │
# │ 3        ┆ 1003     │
# │ 4        ┆ 1004     │
# │ …        ┆ …        │
# │ 49999995 ┆ 50000995 │
# │ 49999996 ┆ 50000996 │
# │ 49999997 ┆ 50000997 │
# │ 49999998 ┆ 50000998 │
# │ 49999999 ┆ 50000999 │
# └──────────┴──────────┘

And the Rust API.

let buf = cache.callback_buffer(
    length, path, etag, 
    |url, range, mut buf| get(url, range).read_into(buf)
);

assert_eq!(buf[10000..10010], b"my s3 data");

Caching

This has a persistent memory mapped lru cache where blocks are downloaded to, making repeated runs and restarts as fast as they would be locally.


TODOS

This is very very rough and not ready for production and only supports macOS.

  • Linux userfaultfd handling
  • Windows API
  • Signal and error handling
  • Prefaulting data.
  • More options around caching.
  • Nonblocking coroutines

Description

Memory map numpy arrays on S3

Related repositories

Similar projects matched by category, topics, and programming language.

l0ng-ai
Featured
l0ng-ai GitHub avatar

tty7

tty7 is a fast, GPU-accelerated terminal workbench with persistent sessions, built-in input tools, SSH support, and coding agent awareness.

Developer ToolsCLI & Terminal
359
steelbrain
Featured
steelbrain GitHub avatar

reims-vgpu

reims-vgpu is an experimental virtual GPU for macOS guests that uses QEMU to decode the guest's GPU command stream and execute it through Metal or Vulkan, leveraging the built-in AppleParavirtGPU driver without requiring custom kexts.

Desktop Apps
143
m-novotny
Featured
m-novotny GitHub avatar

memguard-rs

A Rust library that provides secure memory handling primitives including zeroization on drop, memory locking, constant-time comparison, and compile-time guarded regions, with zero dependencies and no_std support.

Embedded & IoTSecurity
131