Skip to content

internal/mountinfo: create unescaper lazily - #2129

Closed
kolyshkin wants to merge 1 commit into
cilium:mainfrom
kolyshkin:mountinfo-lazy
Closed

kolyshkin wants to merge 1 commit into
cilium:mainfrom
kolyshkin:mountinfo-lazy

Conversation

@kolyshkin

Copy link
Copy Markdown
Contributor

The package-level strings.Replacer is built during package initialization, which happens on every start of any program importing cilium/ebpf (even indirectly, e.g. via asm), regardless of whether mountinfo is ever parsed.

Use sync.OnceValue to only create it when needed.

This reduces internal/mountinfo init time from about 5µs to 1µs (measured with GODEBUG=inittrace=1 on runc, which re-executes itself for every container start/exec).

The package-level strings.Replacer is built during package
initialization, which happens on every start of any program importing
cilium/ebpf (even indirectly, e.g. via asm), regardless of whether
mountinfo is ever parsed.

Use sync.OnceValue to only create it when needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
@kolyshkin
kolyshkin requested a review from a team as a code owner October 14, 2026 00:59
@kolyshkin

Copy link
Copy Markdown
Contributor Author

My bad; strings.NewReplacer is actually lazy by itself, so this is not needed at all.

@kolyshkin kolyshkin closed this Oct 19, 2026
@kolyshkin
kolyshkin deleted the mountinfo-lazy branch October 19, 2026 06:41
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.

1 participant