Skip to content

Expose Regex memory usage info (fixes #943) - #1180

Open
mispecto wants to merge 1 commit into
rust-lang:masterfrom
mispecto:regex_memory_usage_fn
Open

Expose Regex memory usage info (fixes #943)#1180
mispecto wants to merge 1 commit into
rust-lang:masterfrom
mispecto:regex_memory_usage_fn

Conversation

@mispecto

@mispecto mispecto commented Apr 5, 2024

Copy link
Copy Markdown

No description provided.

@ambyjkl

ambyjkl commented Aug 29, 2024

Copy link
Copy Markdown

@BurntSushi sorry for the ping but I wanted to bring your attention to this PR, it would be great if this could get merged

@ambyjkl

ambyjkl commented Aug 29, 2024

Copy link
Copy Markdown

@spektom can you also expose the function on RegexSet?

@BurntSushi

Copy link
Copy Markdown
Member

I have concerns about this that I explained in #943. Those need to be resolved first.

@ambyjkl

ambyjkl commented Aug 29, 2024

Copy link
Copy Markdown

I have concerns about this that I explained in #943. Those need to be resolved first.

That's fair, maybe a better name would be memory_usage_estimate with some warnings about potential caveats. My use case doesn't need precise figures, I want to use this memory usage estimate as weights in a weighted cache, so all I need is the ratio of memory usage between two regexes, not an absolute value.

@LuisDuarte1

Copy link
Copy Markdown

I have almost the same usecase as @ambyjkl - I basically want a "LRU cache" of regex rules as I'm in a semi-constrained memory environment. In my opinion, calling it memory_usage_estimate is more than good enough providing we document it properly.

@BurntSushi BurntSushi mentioned this pull request Aug 23, 2025
@typetetris

Copy link
Copy Markdown

Having a function like memory_usage_estimate for the exact same reason of having a size based cache would be very helpful to me, too.

At the moment I use regex-automata directly for that purpose and need to copy some stuff from the regex crate.

@ashdnazg

Copy link
Copy Markdown

I also have the exact same caching motivation.

@BurntSushi Any way to help push this beyond suggesting names? I think we'd all be happy with any of memory|heap|allocated with any of usage|bytes etc. (avoid using size to make it clear it is not about the size limit), add approximate|estimated before or estimate after, and that should be fine.

IMO best is approximate_allocated_bytes since even though it's quite the mouthful, it sounds like it has nothing to do with the size limit.

@BurntSushi

Copy link
Copy Markdown
Member

I think memory_usage is probably good enough of a name. But the documentation should specifically call out that this isn't related to RegexBuilder::size_limit. That is, one cannot count on memory_usage() < RegexBuilder::size_limit().

@ashdnazg

Copy link
Copy Markdown

I opened a new PR #1377 since I can't update this one.

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.

6 participants