Skip to content

Optimizes private key normalization #4224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Optimizes private key normalization #4224

wants to merge 4 commits into from

Conversation

ahrav
Copy link
Collaborator

@ahrav ahrav commented Jun 13, 2025

  • Overview:
    Implements a single-pass approach to normalize private key strings by replacing multiple escape and platform-specific sequences using a canonical mapping.

Screenshot 2025-06-13 at 2 25 41 PM

Benchmarks (I was mainly interested in the reduced allocations)

Screenshot 2025-06-13 at 2 23 58 PM

NOTE: I see the LDAP detector also causing memory issues. I'll tackle that one next in a separate PR.

@ahrav ahrav requested a review from a team June 13, 2025 21:30
@ahrav ahrav marked this pull request as ready for review June 13, 2025 21:48
@ahrav ahrav requested a review from a team as a code owner June 13, 2025 21:48
result.Grow(len(raw))

// Normalize per-line whitespace and discard blank lines.
lines := strings.Split(raw, "\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how memory usage decreases by minimizing allocations because they have overhead, but I would guess a bigger source of memory usage is building a new array of the whole string here. If you change this loop to use strings.Find to iterate through the string line by line you can probably halve memory usage. It's more tedious and harder to read, but such is the nature of optimizing I guess.

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.

3 participants