From 475bdb902149557aa5cc744f0645d11fd5add1de Mon Sep 17 00:00:00 2001 From: Zlatoslav Desiatnikov Date: Sun, 22 Mar 2026 15:08:59 +0300 Subject: [PATCH] perf: use uuid v7 instead of uuid v4 --- oryx/networkx/network.go | 2 +- oryx/sqlxx/batch/create.go | 2 +- oryx/uuidx/uuid.go | 4 ++++ persistence/sql/batch/create.go | 2 +- persistence/sql/identity/persister_identity.go | 2 +- persistence/sql/persister_courier.go | 2 +- x/uuid.go | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/oryx/networkx/network.go b/oryx/networkx/network.go index e9be9276aeee..0461d6f43ccb 100644 --- a/oryx/networkx/network.go +++ b/oryx/networkx/network.go @@ -25,6 +25,6 @@ func (p Network) TableName() string { func NewNetwork() *Network { return &Network{ - ID: uuid.Must(uuid.NewV4()), + ID: uuid.Must(uuid.NewV7()), } } diff --git a/oryx/sqlxx/batch/create.go b/oryx/sqlxx/batch/create.go index a297e98e3c57..e2edec29bd41 100644 --- a/oryx/sqlxx/batch/create.go +++ b/oryx/sqlxx/batch/create.go @@ -146,7 +146,7 @@ func buildInsertQueryValues[T any](dialect string, mapper *reflectx.Mapper, colu continue // break switch, not for } - id, err := uuid.NewV4() + id, err := uuid.NewV7() if err != nil { return nil, err } diff --git a/oryx/uuidx/uuid.go b/oryx/uuidx/uuid.go index e405746dacae..6621a4005041 100644 --- a/oryx/uuidx/uuid.go +++ b/oryx/uuidx/uuid.go @@ -9,3 +9,7 @@ import "github.com/gofrs/uuid" func NewV4() uuid.UUID { return uuid.Must(uuid.NewV4()) } + +func NewV7() uuid.UUID { + return uuid.Must(uuid.NewV7()) +} diff --git a/persistence/sql/batch/create.go b/persistence/sql/batch/create.go index f869ca36b86f..0759ac0720dd 100644 --- a/persistence/sql/batch/create.go +++ b/persistence/sql/batch/create.go @@ -167,7 +167,7 @@ func buildInsertQueryValues[T any](columns []string, models []*T, opts *createOp continue // break switch, not for } - id, err := uuid.NewV4() + id, err := uuid.NewV7() if err != nil { return nil, err } diff --git a/persistence/sql/identity/persister_identity.go b/persistence/sql/identity/persister_identity.go index 0422bea6f22c..bbdea09d6c18 100644 --- a/persistence/sql/identity/persister_identity.go +++ b/persistence/sql/identity/persister_identity.go @@ -308,7 +308,7 @@ func (p *IdentityPersister) createIdentityCredentials(ctx context.Context, ident return err } - cred.ID, err = uuid.NewV4() + cred.ID, err = uuid.NewV7() if err != nil { return err } diff --git a/persistence/sql/persister_courier.go b/persistence/sql/persister_courier.go index e3be52fe7082..13a4b59fd995 100644 --- a/persistence/sql/persister_courier.go +++ b/persistence/sql/persister_courier.go @@ -191,7 +191,7 @@ func (p *Persister) RecordDispatch(ctx context.Context, msgID uuid.UUID, status defer otelx.End(span, &err) dispatch := courier.MessageDispatch{ - ID: uuidx.NewV4(), + ID: uuidx.NewV7(), MessageID: msgID, Status: status, NID: p.NetworkID(ctx), diff --git a/x/uuid.go b/x/uuid.go index 19406a2ea81b..e6084046582d 100644 --- a/x/uuid.go +++ b/x/uuid.go @@ -10,7 +10,7 @@ import ( var EmptyUUID uuid.UUID func NewUUID() uuid.UUID { - return uuid.Must(uuid.NewV4()) + return uuid.Must(uuid.NewV7()) } func ParseUUID(in string) uuid.UUID {