Skip to content

Conversation

onshorechet
Copy link
Contributor

This changeset implements these interfaces found in the encoding package:  

  • MarshalBinary() (data []byte, err error)
     - UnmarshalBinary(data []byte) error
     - AppendBinary(b []byte) ([]byte, error)
     - MarshalText() (text []byte, err error)
     - UnmarshalText(text []byte) error
     - AppendText(b []byte) ([]byte, error)

ParseUUID and uuid.String are now implemented in terms of these new methods. UnmarshalText and AppendText use algorithms inspired by the hex package. Also the UUID.String method has been optimized to avoid allocations by using unsafe.String. Finally the new UnmarshalText supports 128, 32 and 16 bit uuids.

Additional tests were added to verify the new methods and some existing methods missing coverage.

Benchmark results (using benchstat, 10 runs each):
 - ParseUUID:  ~71.04% faster (p=0.000, n=10)
 - UUID.String(): ~81.26% faster (p=0.000, n=10)
 - UUID.String(): Memory allocations reduced by 100% (48 B/op to 0 B/op)

…mance

This changeset implements these interfaces found in the encoding package:
 - MarshalBinary() (data []byte, err error)
 - UnmarshalBinary(data []byte) error
 - AppendBinary(b []byte) ([]byte, error)
 - MarshalText() (text []byte, err error)
 - UnmarshalText(text []byte) error
 - AppendText(b []byte) ([]byte, error)

ParseUUID and uuid.String are now implemented in terms of these new
methods.  UnmarshalText and AppendText use algorithms inspired by
the hex package. Also the UUID.String method has been optimized
to avoid allocations by using unsafe.String.
Finally the new UnmarshalText supports 128, 32 and 16 bit uuids.

Additional tests were added to verify the new methods and some existing methods
missing coverage.

Benchmark results (using benchstat, 10 runs each):
 - `ParseUUID`:  ~71.04% faster (p=0.000, n=10)
 - `UUID.String()`: ~81.26% faster (p=0.000, n=10)
 - `UUID.String()`: Memory allocations reduced by 100% (48 B/op to 0 B/op)
@deadprogram
Copy link
Member

Thank you very much for such a complete PR @onshorechet and for the excellent responses to my little feedback items. Great work!

Now merging, thanks again.

@deadprogram deadprogram merged commit 0d1c723 into tinygo-org:dev Mar 11, 2025
4 checks passed
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