Skip to content

Commit 349b579

Browse files
committed
fix: optimize UUIDToBlob allocation, sort async map iterations
1 parent 62ce850 commit 349b579

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

mdl/types/asyncapi.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package types
44

55
import (
66
"fmt"
7+
"sort"
78
"strings"
89

910
"gopkg.in/yaml.v3"
@@ -61,8 +62,14 @@ func ParseAsyncAPI(yamlStr string) (*AsyncAPIDocument, error) {
6162
Description: raw.Info.Description,
6263
}
6364

64-
// Resolve messages from components
65-
for name, msg := range raw.Components.Messages {
65+
// Resolve messages from components (sorted for deterministic output)
66+
messageNames := make([]string, 0, len(raw.Components.Messages))
67+
for name := range raw.Components.Messages {
68+
messageNames = append(messageNames, name)
69+
}
70+
sort.Strings(messageNames)
71+
for _, name := range messageNames {
72+
msg := raw.Components.Messages[name]
6673
resolved := &AsyncAPIMessage{
6774
Name: name,
6875
Title: msg.Title,
@@ -88,8 +95,14 @@ func ParseAsyncAPI(yamlStr string) (*AsyncAPIDocument, error) {
8895
doc.Messages = append(doc.Messages, resolved)
8996
}
9097

91-
// Resolve channels
92-
for channelName, channel := range raw.Channels {
98+
// Resolve channels (sorted for deterministic output)
99+
channelNames := make([]string, 0, len(raw.Channels))
100+
for name := range raw.Channels {
101+
channelNames = append(channelNames, name)
102+
}
103+
sort.Strings(channelNames)
104+
for _, channelName := range channelNames {
105+
channel := raw.Channels[channelName]
93106
if channel.Subscribe != nil {
94107
msgName := ""
95108
if channel.Subscribe.Message.Ref != "" {
@@ -138,8 +151,14 @@ func asyncRefName(ref string) string {
138151
}
139152

140153
func resolveAsyncSchemaProperties(schema yamlAsyncSchema) []*AsyncAPIProperty {
154+
names := make([]string, 0, len(schema.Properties))
155+
for name := range schema.Properties {
156+
names = append(names, name)
157+
}
158+
sort.Strings(names)
141159
var props []*AsyncAPIProperty
142-
for name, prop := range schema.Properties {
160+
for _, name := range names {
161+
prop := schema.Properties[name]
143162
props = append(props, &AsyncAPIProperty{
144163
Name: name,
145164
Type: prop.Type,

mdl/types/id.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ func UUIDToBlob(uuid string) []byte {
5454
return nil
5555
}
5656
var clean strings.Builder
57+
clean.Grow(32)
5758
for _, c := range uuid {
5859
if c != '-' {
59-
clean.WriteString(string(c))
60+
clean.WriteByte(byte(c))
6061
}
6162
}
6263
decoded, err := hex.DecodeString(clean.String())

0 commit comments

Comments
 (0)