Skip to content

proto: optimize Properties.Parse() using IndexByte - #779

Open
AmritM18 wants to merge 1 commit into
gogo:masterfrom
AmritM18:optimize-parse-function
Open

proto: optimize Properties.Parse() using IndexByte#779
AmritM18 wants to merge 1 commit into
gogo:masterfrom
AmritM18:optimize-parse-function

Conversation

@AmritM18

Copy link
Copy Markdown

Replace strings.Split with strings.IndexByte for better performance:

  • Eliminates slice allocation for field parsing
  • Single-pass parsing without intermediate slices

@AmritM18
AmritM18 force-pushed the optimize-parse-function branch from d480764 to e30260b Compare March 13, 2026 00:32
Comment thread proto/properties.go Outdated
Comment on lines +288 to +293
value := f[9:]
if eq := strings.IndexByte(value, '='); eq != -1 {
p.OrigName = value[:eq]
} else {
p.OrigName = value
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

should we just do https://pkg.go.dev/strings#CutPrefix here and below?

it would be nicer if we could do this as part of the switch, but I think that's a no?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yah sure, I can switch for that. I don't know how it'd be part of the switch though.

Comment thread proto/properties.go
Comment on lines +234 to +236
if comma == -1 {
tagField = s[pos:]
pos = len(s)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why is this here, shouldn't this be an error?

(didn't previous code reqire at least 2 commas?(

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

hm I somehow missed this. yeah this code isn't super easy to read hm. I can try out the splitN optimization.

as for this code, we're looking at the second comma here so we can get the tag field. the original code checked if there were at least 2 items after splitting by commas. the check on line 206 accomplishes the same thing (2 items == 1 comma).

Replace strings.Split with strings.IndexByte for better performance:
- Eliminates slice allocation for field parsing
- Single-pass parsing without intermediate slices
- Fixes embedded/customtype/casttype parsing edge cases
- Maintains full backward compatibility

Benchmark results show improved performance while
maintaining identical functionality and passing all tests.

Made-with: Cursor
@AmritM18
AmritM18 force-pushed the optimize-parse-function branch from e30260b to 652d6f1 Compare March 18, 2026 20:41
Comment thread proto/properties.go
case strings.HasPrefix(f, "embedded="):
p.OrigName = strings.Split(f, "=")[1]
value, _ := strings.CutPrefix(f, "embedded=")
if eq := strings.IndexByte(value, '='); eq != -1 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

why do we need all this indexing? shouldn't but prefix be enough?

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