uv/crates
konsti 47fc90d1b3
Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004)
This is https://github.com/astral-sh/puffin/pull/947 again but this time
merging into main instead of downstack, sorry for the noise.

---

Windows has a default stack size of 1MB, which makes puffin often fail
with stack overflows. The PR reduces stack size by three changes:

* Boxing `File` in `Dist`, reducing the size from 496 to 240.
* Boxing the largest futures.
* Boxing `CachePolicy`

## Method

Debugging happened on linux using
https://github.com/astral-sh/puffin/pull/941 to limit the stack size to
1MB. Used ran the command below.

```
RUSTFLAGS=-Zprint-type-sizes cargo +nightly build -p puffin-cli -j 1 > type-sizes.txt && top-type-sizes -w -s -h 10 < type-sizes.txt > sizes.txt
```

The main drawback is top-type-sizes not saying what the `__awaitee` is,
so it requires manually looking up with a future with matching size.

When the `brotli` features on `reqwest` is active, a lot of brotli types
show up. Toggling this feature however seems to have no effect. I assume
they are false positives since the `brotli` crate has elaborate control
about allocation. The sizes are therefore shown with the feature off.

## Results

The largest future goes from 12208B to 6416B, the largest type
(`PrioritizedDistribution`, see also #948) from 17448B to 9264B. Full
diff: https://gist.github.com/konstin/62635c0d12110a616a1b2bfcde21304f

For the second commit, i iteratively boxed the largest file until the
tests passed, then with an 800KB stack limit looked through the
backtrace of a failing test and added some more boxing.

Quick benchmarking showed no difference:

```console
$ hyperfine --warmup 2 "target/profiling/main-dev resolve meine_stadt_transparent" "target/profiling/puffin-dev resolve meine_stadt_transparent" 
Benchmark 1: target/profiling/main-dev resolve meine_stadt_transparent
  Time (mean ± σ):      49.2 ms ±   3.0 ms    [User: 39.8 ms, System: 24.0 ms]
  Range (min … max):    46.6 ms …  63.0 ms    55 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: target/profiling/puffin-dev resolve meine_stadt_transparent
  Time (mean ± σ):      47.4 ms ±   3.2 ms    [User: 41.3 ms, System: 20.6 ms]
  Range (min … max):    44.6 ms …  60.5 ms    62 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Summary
  target/profiling/puffin-dev resolve meine_stadt_transparent ran
    1.04 ± 0.09 times faster than target/profiling/main-dev resolve meine_stadt_transparent
```
2024-01-19 09:38:36 +00:00
..
bench Use Clippy lint table over Cargo config (#490) 2023-11-22 15:10:27 +00:00
cache-key Avoid storing absolute URLs for files (#944) 2024-01-17 09:15:21 -05:00
distribution-filename Implement --find-links as flat indexes (directories in pip-compile) (#912) 2024-01-15 02:04:10 +00:00
distribution-types Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
gourgeist Normalize base python in venv creation (#966) 2024-01-18 15:32:30 +00:00
install-wheel-rs Validate wheel metadata against filename (#1002) 2024-01-19 05:48:55 +00:00
once-map Move OnceMap into its own crate (#946) 2024-01-17 04:09:15 +00:00
pep440-rs Add release workflow (#961) 2024-01-18 15:44:11 -05:00
pep508-rs Fix pep508_rs doc test (#963) 2024-01-18 14:24:30 +00:00
platform-host Error when ldd is not in path (#506) 2023-11-28 05:55:04 +00:00
platform-tags Cache Tags on Interpreter (#726) 2023-12-25 13:41:10 +00:00
puffin Add an env var to artificially limit the stack size (#941) 2024-01-19 09:34:46 +00:00
puffin-build Default to PEP 517-based builds (#843) 2024-01-10 01:27:06 +00:00
puffin-cache Mark path-based cache entries as stale during install plan (#957) 2024-01-18 19:13:29 +00:00
puffin-client Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
puffin-dev Add Puffin Docker image (#985) 2024-01-18 20:21:31 -05:00
puffin-dispatch Split install plan into builder and struct (#955) 2024-01-17 15:28:46 -05:00
puffin-distribution Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
puffin-extract Use fs_err in more places (#926) 2024-01-15 09:39:33 +00:00
puffin-fs Show resource and lockfile when waiting (#715) 2023-12-21 00:05:49 +01:00
puffin-git Split puffin-cache into Puffin-specific and generic utilities (#728) 2023-12-25 14:38:56 +00:00
puffin-installer Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
puffin-interpreter Adjust markers to match target Python version (#909) 2024-01-14 15:39:15 +00:00
puffin-normalize Avoid some additional clones for PackageName (#896) 2024-01-12 17:54:40 +00:00
puffin-resolver Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
puffin-traits Reduce stack usage by boxing File in Dist, CachePolicy and large futures (#1004) 2024-01-19 09:38:36 +00:00
puffin-warnings Migrate back to owo-colors (#824) 2024-01-08 08:54:57 +00:00
puffin-workspace Use Clippy lint table over Cargo config (#490) 2023-11-22 15:10:27 +00:00
pypi-types Remove RFC2047 decoder (#967) 2024-01-18 15:09:45 -05:00
requirements-txt Remove unused path method (#974) 2024-01-18 21:59:12 +00:00
README.md Rename puffin-cli crate to puffin (#976) 2024-01-18 19:02:52 -05:00

Crates

bench

Functionality for benchmarking Puffin.

cache-key

Generic functionality for caching paths, URLs, and other resources across platforms.

distribution-filename

Parse built distribution (wheel) and source distribution (sdist) filenames to extract structured metadata.

distribution-types

Abstractions for representing built distributions (wheels) and source distributions (sdists), and the sources from which they can be downloaded.

gourgeist

A venv replacement to create virtual environments in Rust.

install-wheel-rs

Install built distributions (wheels) into a virtual environment.]

once-map

A waitmap-like concurrent hash map for executing tasks exactly once.

pep440-rs

Utilities for interacting with Python version numbers and specifiers.

pep508-rs

Utilities for interacting with PEP 508 dependency specifiers.

platform-host

Functionality for detecting the current platform (operating system, architecture, etc.).

platform-tags

Functionality for parsing and inferring Python platform tags as per PEP 425.

puffin

Command-line interface for the Puffin package manager.

puffin-build

A PEP 517-compatible build frontend for Puffin.

puffin-cache

Functionality for caching Python packages and associated metadata.

puffin-client

Client for interacting with PyPI-compatible HTTP APIs.

puffin-dev

Development utilities for Puffin.

puffin-dispatch

A centralized struct for resolving and building source distributions in isolated environments. Implements the traits defined in puffin-traits.

puffin-distribution

Client for interacting with built distributions (wheels) and source distributions (sdists). Capable of fetching metadata, distribution contents, etc.

puffin-extract

Utilities for extracting files from archives.

puffin-fs

Utilities for interacting with the filesystem.

puffin-git

Functionality for interacting with Git repositories.

puffin-installer

Functionality for installing Python packages into a virtual environment.

puffin-interpreter

Functionality for detecting and leveraging the current Python interpreter.

puffin-normalize

Normalize package and extra names as per Python specifications.

puffin-package

Types and functionality for working with Python packages, e.g., parsing wheel files.

puffin-resolver

Functionality for resolving Python packages and their dependencies.

puffin-traits

Shared traits for Puffin, to avoid circular dependencies.

pypi-types

General-purpose type definitions for types used in PyPI-compatible APIs.

puffin-warnings

User-facing warnings for Puffin.

requirements-txt

Functionality for parsing requirements.txt files.