diff --git a/atproto/syntax/uri.go b/atproto/syntax/uri.go index fbf8807c..61165b25 100644 --- a/atproto/syntax/uri.go +++ b/atproto/syntax/uri.go @@ -5,6 +5,8 @@ import ( "regexp" ) +var uriRegex = regexp.MustCompile(`^[a-z][a-z.-]{0,80}:[[:graph:]]+$`) + // Represents an arbitrary URI in string format, as would pass Lexicon syntax validation. // // The syntax is minimal and permissive, designed for fast verification and exact-string passthrough, not schema-specific parsing or validation. For example, will not validate AT-URI or DID strings. @@ -19,7 +21,6 @@ func ParseURI(raw string) (URI, error) { if len(raw) > 8192 { return "", errors.New("URI is too long (8192 chars max)") } - var uriRegex = regexp.MustCompile(`^[a-z][a-z.-]{0,80}:[[:graph:]]+$`) if !uriRegex.MatchString(raw) { return "", errors.New("URI syntax didn't validate via regex") } -- 2.51.2 From 6755517c451632d48fbdd05683467a1ae7300720 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 8 Apr 2026 13:37:58 -0700 Subject: [PATCH 2/3] syntax: remove wasteful string construction in NewTIDFromInteger() --- atproto/syntax/tid.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atproto/syntax/tid.go b/atproto/syntax/tid.go index bebb8467..01494397 100644 --- a/atproto/syntax/tid.go +++ b/atproto/syntax/tid.go @@ -48,12 +48,12 @@ func NewTIDNow(clockId uint) TID { func NewTIDFromInteger(v uint64) TID { v = (0x7FFF_FFFF_FFFF_FFFF & v) - s := "" - for i := 0; i < 13; i++ { - s = string(Base32SortAlphabet[v&0x1F]) + s + var buf [13]byte + for i := 12; i >= 0; i-- { + buf[i] = Base32SortAlphabet[v&0x1F] v = v >> 5 } - return TID(s) + return TID(buf[:]) } // Constructs a new TID from a UNIX timestamp (in milliseconds) and clock ID value. -- 2.51.2 From 1f59f69bfec7bd5e35fc1bf61e332ba642057c6c Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Wed, 8 Apr 2026 13:38:28 -0700 Subject: [PATCH 3/3] syntax: basic bench tests --- atproto/syntax/bench_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 atproto/syntax/bench_test.go diff --git a/atproto/syntax/bench_test.go b/atproto/syntax/bench_test.go new file mode 100644 index 00000000..ebcee1f2 --- /dev/null +++ b/atproto/syntax/bench_test.go @@ -0,0 +1,18 @@ +package syntax + +import "testing" + +func BenchmarkParseURI(b *testing.B) { + for b.Loop() { + _, _ = ParseURI("https://example.com/path?query=1#fragment") + } + b.ReportAllocs() +} + +func BenchmarkTIDClock_Next(b *testing.B) { + clock := NewTIDClock(1) + for b.Loop() { + _ = clock.Next() + } + b.ReportAllocs() +}