Skip to content

Add memory pre-checks to padding, replace and f-string operations#238

Merged
samuelcolvin merged 1 commit intomainfrom
nm/str-bytes-mem-checks
Mar 4, 2026
Merged

Add memory pre-checks to padding, replace and f-string operations#238
samuelcolvin merged 1 commit intomainfrom
nm/str-bytes-mem-checks

Conversation

@MRoci
Copy link
Contributor

@MRoci MRoci commented Mar 4, 2026

Operations like f-string formatting, str.replace, str.ljust, str.center, str.rjust, str.zfill (and their bytes equivalents) allocated result strings (or Vecs) on the Rust heap before allocate_string/allocate_bytes could check against the ResourceTracker.

This meant LimitedTracker's max_memory was ineffective for these operations.

Adds check_replace_size pre-check and reuses check_repeat_size for padding to estimate result size before allocating and reject if it exceeds memory limits.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 4, 2026

Merging this PR will not alter performance

✅ 13 untouched benchmarks


Comparing nm/str-bytes-mem-checks (899ff10) with main (4ee3fd7)

Open in CodSpeed

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MRoci MRoci force-pushed the nm/str-bytes-mem-checks branch from 70fccb3 to 71cad5c Compare March 4, 2026 09:53
Operations like f-string formatting, str.replace, str.ljust, str.center, str.rjust,
str.zfill (and their bytes equivalents) allocated result strings
(or Vecs) on the Rust heap before allocate_string/allocate_bytes could check
against the ResourceTracker.

This meant LimitedTracker's max_memory was ineffective for these operations.

Adds check_replace_size pre-check and reuses check_repeat_size for padding to estimate result size before allocating and reject if it exceeds memory limits.
@MRoci MRoci force-pushed the nm/str-bytes-mem-checks branch from 71cad5c to 899ff10 Compare March 4, 2026 10:09
@samuelcolvin samuelcolvin merged commit bf7c7ef into main Mar 4, 2026
24 checks passed
@samuelcolvin samuelcolvin deleted the nm/str-bytes-mem-checks branch March 4, 2026 10:36
@samuelcolvin
Copy link
Member

awesome, thank you.

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.

2 participants