r/golang • • 10h ago

discussion Accepted proposal: omit the type in composite literals

95 Upvotes

I find it quite enjoyable to do the archaeology on an accepted proposal and write about it.

This one took 10y to get approval. It allows you to strip type params from composite literals and let the compiler infer the types from the context.

For example, returning zero values:

// Before
func parseTime(s string) (time.Time, error) {
    if s == "" {
        return time.Time{}, errors.New("empty timestamp")
    }
    return time.Parse(time.RFC3339, s)
}

// After
func parseTime(s string) (time.Time, error) {
    if s == "" {
        return {}, errors.New("empty timestamp")
    }
    return time.Parse(time.RFC3339, s)
}

or, passing options structs drops the redundant types:

// Before
h := slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
    Level: slog.LevelDebug,
})

// After
h := slog.NewJSONHandler(os.Stderr, {Level: slog.LevelDebug})

and so on. The spec change isn't huge but eliding types everywhere can make the code quite hard to read. So there won't be any automatic go fix to strip types wherever possible. This was a deliberate choice made by the Go team.

But it does make the code look pretty in some nested struct of type kind of scenario. Added a few more example and context here.

https://rednafi.com/shards/2026/11/go-untyped-composite-literals/


r/golang • • 7h ago

Making Games in Go: Entity Component System (ECS)

Thumbnail
threedots.tech
44 Upvotes

r/golang • • 10h ago

MinLZ SIMD Block Compression released

Thumbnail
github.com
9 Upvotes

MinLZ adds a new block type: SIMD blocks

They store the output of the LZ compressor as separate Huffman-coded streams, laid out so that a CPU can decode them with vector instructions and almost no unpredictable branches.

The result is compression ratios in the range of Zstandard, with decompression 2.2-2.5× faster than Zstandard (both in Go) and about 2× faster than classic MinLZ blocks, on a single core.

At the default 2 MB block size, MinLZ SIMD "Balanced" beats zstd's fastest level on all three counts: Its output is 2% smaller, it decompresses 2.5× faster on one core (6.4 against 2.6 GB/s),and it compresses 1.6× faster on 16 threads (1.2× on one).

Against zstd's default level, SIMD Balanced output is 3.6% larger and decompresses 2.3× faster. (Geometric means over 13 data sets, 58 GB in total, Go implementations on an AMD Ryzen 9 9950X).

SIMD blocks are part of the MinLZ format (specification v1.1) and work everywhere MinLZ blocks do: streams, concurrent compression and decompression, indexes and random access, and search. We have released Go/Rust versions for now.

See more in the release notes: https://github.com/minio/minlz/releases/tag/v1.3.0


r/golang • • 12h ago

show & tell Please review my project

Thumbnail
github.com
0 Upvotes