<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ajitem Sahasrabuddhe on Medium]]></title>
        <description><![CDATA[Stories by Ajitem Sahasrabuddhe on Medium]]></description>
        <link>https://medium.com/@ajitem?source=rss-33fcdacba2f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9p3ckQJ4RU7sDNMHcVBF9Q.jpeg</url>
            <title>Stories by Ajitem Sahasrabuddhe on Medium</title>
            <link>https://medium.com/@ajitem?source=rss-33fcdacba2f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 01:52:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ajitem/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[My Journey Through the One Billion Row Challenge in Go]]></title>
            <link>https://medium.com/technogise/my-journey-through-the-one-billion-row-challenge-in-go-96a97484ddf7?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/96a97484ddf7</guid>
            <category><![CDATA[performance-engineering]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[devex]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Tue, 15 Apr 2025 10:18:00 GMT</pubDate>
            <atom:updated>2025-04-15T10:21:04.928Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is the One Billion Row Challenge?</h3><p>The 1 Billion Row Challenge is a benchmark exercise that tests how well a system can handle, process, and query a massive dataset containing one billion rows. The idea is to push the limits of data ingestion, memory usage, CPU performance, and query optimization in a real-world scenario where scale matters. It’s a practical way to explore performance bottlenecks and experiment with optimizations when dealing with truly large datasets. You can check out the original repository for the challenge here: <a href="https://github.com/gunnarmorling/1brc">https://github.com/gunnarmorling/1brc</a>.</p><p>When the One Billion Row Challenge was announced in January 2024, I was immediately captivated by the idea of harnessing Go to process a massive dataset as efficiently as possible — even though the challenge was originally meant for Java. I first dipped my toes into the challenge during March–April 2024, but my initial attempt didn’t hit the performance marks I was aiming for. It wasn’t until I attended Gophercon 2024 and watched an inspiring talk on the topic (<a href="https://www.youtube.com/watch?v=Ti8EryJOqNk">Gophercon 2024 Talk</a>) that my passion was reignited. With fresh insights and renewed determination, I set out to optimize my solution once again — iterating through eight distinct versions until I finally achieved a processing time of just <strong>3.08 seconds</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AHDmEGu1w-X9yibP0Yq0SA@2x.png" /><figcaption>My challenge timings</figcaption></figure><h3>The Evolution of My Solution</h3><p>My journey began with a straightforward, idiomatic Go solution. Over time, I incorporated various optimizations aimed at reducing overhead, leveraging concurrency, and fine-tuning data structures.</p><h3>v1 — The Baseline</h3><p>In my initial version, I relied on the standard library functions such as strings.Splitand bufio.Scanner to parse the file. While this implementation was easy to write, it quickly became apparent that the standard library’s convenience came at a performance cost. That said, <strong>this is by no means a recommendation to avoid using the standard library — its functions are robust and cover a wide range of edge cases. The custom optimizations were only considered for an extreme case like this, where the data is well-defined and under set bounds</strong>.</p><h3>v2 &amp; v3 — Eliminating Unnecessary Overhead</h3><p>In version 2, I removed strings.Split to avoid extra string allocations, and in version 3, I replaced bufio.Scanner with a more controlled reading mechanism. These changes laid the groundwork for more substantial improvements later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*7tWB1dMBjaQmzZFZUIB3RA@2x.png" /><figcaption>I replaced strings.Split with a custom function that locates the separator index and directly manipulates the incoming byte slice.</figcaption></figure><pre>func lastByteIndex(in []byte, n byte) int {<br>    for i := len(in) - 1; i &gt;= 0; i-- {<br>       if in[i] == n {<br>          return i<br>       }<br>    }<br>    return -1<br>}</pre><pre>buf := make([]byte, BufferSize)<br>readStart := 0<br>for {<br>  n, readErr := in.Read(buf[readStart:])<br>  if readErr != nil &amp;&amp; !errors.Is(readErr, io.EOF) {<br>    panic(readErr)<br>  }<br>  if readStart+n == 0 {<br>    break<br>  }<br>  chunk := buf[:readStart+n]<br>  newLine := bytes.LastIndexByte(chunk, &#39;\n&#39;)<br>  if newLine &lt; 0 {<br>    break<br>  }<br><br>  remaining := chunk[newLine+1:]<br>  chunk = chunk[:newLine+1]<br><br>  start := 0<br>  for i := 0; i &lt; len(chunk); i++ {<br>    // process the chunk<br>  }<br>  readStart = copy(buf, remaining)<br>}</pre><p>This approach pre-allocates a buffer that is reused in subsequent iterations, avoiding repeated memory allocations and reducing the frequency of garbage collection calls.</p><h3>v4 — Custom Parsing and Data Type Tweaks</h3><p>Realizing that the standard library parsing functions were slowing me down, I wrote a custom parser to convert strings to int64 and swapped out float64 for int64 wherever possible. Here’s a snippet from my custom parser:</p><pre>// Custom parser snippet from v4:<br>var isNeg bool<br>var temp int64<br>index := 0<br><br>if chunk[0] == &#39;-&#39; {<br>    isNeg = true<br>    index++<br>}<br>for ; index &lt; len(chunk); index++ {<br>    if chunk[index] == &#39;\n&#39; {<br>        break<br>    }<br>    if chunk[index] == &#39;.&#39; {<br>        // Skip the decimal point.<br>        continue<br>    }<br>    temp = temp*10 + int64(chunk[index]-&#39;0&#39;)<br>}<br>if isNeg {<br>    temp = -temp<br>}</pre><h3>v5 — Harnessing the Power of Concurrency</h3><p>I knew that Go’s concurrency model could be a game changer. In version 5, I restructured the program to split the input file into chunks and process each concurrently in its own goroutine. This change reduced the processing time dramatically — from minutes to just 11 seconds. Here’s how I set up the concurrent processing:</p><pre>// Launching goroutines for each chunk in v5:<br>chunks, err := splitChunks(fileName, runtime.NumCPU())<br>if err != nil {<br>    return err<br>}<br><br>resultsCh := make(chan *hashBucket)<br>var chunkWg sync.WaitGroup<br>chunkWg.Add(len(chunks))<br>for _, chunk := range chunks {<br>    go processChunk(fileName, chunk, resultsCh, &amp;chunkWg)<br>}<br><br>go func() {<br>    chunkWg.Wait()<br>    close(resultsCh)<br>}()</pre><h3>v6 — Optimizing Data Structures</h3><p>Version 6 involved reducing the overhead associated with frequent map accesses. By using pointers to streamline memory access, I managed to shave the execution time down further to 5.7 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*bLAYprss0kziJtb7v-WfTg@2x.png" /><figcaption>I’ swapped the map’s value type from DataV4 to *DataV4 to reduce overhead on map operations and improve performance</figcaption></figure><h3>v7 — Custom Hash Buckets with FNV-1</h3><p>In v7, I replaced Go’s standard map with a custom hash bucket implementation using the <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1_hash">FNV-1</a> hash algorithm. This not only boosted speed but also improved the memory access pattern. Below is an excerpt from my process_v7.go file:</p><pre>// Excerpt from process_v7.go showing FNV-1 hash computation:<br>var hash uint64 = offset64<br>for i := 0; i &lt; len(chunk); i++ {<br>    c := chunk[i]<br>    if c == &#39;;&#39; {<br>        stationName, chunk = chunk[:i], chunk[i+1:]<br>        break<br>    }<br>    hash *= prime64<br>    hash ^= uint64(c)<br>}</pre><p>This custom implementation allowed me to merge results from multiple goroutines efficiently and sort the final output by station name.</p><p><a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1_hash">FNV-1</a> was chosen as the hashing algorithm because it efficiently produces a numerical hash, making it easy to generate an index for our hash bucket. Its simplicity and speed, combined with a good balance between distribution quality and performance, make it ideal for scenarios where fast, non-cryptographic hashing is required. Unlike more complex algorithms, <a href="https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1_hash">FNV-1</a> ensures minimal collisions while maintaining a lightweight computational footprint, making it well-suited for hash table indexing.</p><h3>v8 — Final Optimization with Profile Guided Optimization (PGO)</h3><p>The latest iteration, v8, saw me leveraging Profile Guided Optimization (PGO) to generate an even more refined binary. Although the performance improvement from v7 was incremental, PGO brought the execution time down to an impressive <strong>3.08 seconds</strong>. This final tweak underscored that even after extensive code-level optimizations, advanced compiler techniques can still extract additional performance gains.</p><pre>go build -o 1brc -pgo profiles/v8.out cmd/1brc.go</pre><h3>Performance Metrics</h3><p>Here’s a quick look at the performance improvements achieved from v1 through v8:</p><ul><li><strong>Execution Time:</strong> Reduced from 148.46 seconds to 3.08 seconds (a 97.92% improvement).</li><li><strong>Memory Usage:</strong> Dropped from approximately 45GB to just 321MB (a 99.31% reduction).</li><li><strong>Allocation Efficiency:</strong> Memory allocations decreased from 2GB per operation to just 11KB per operation.</li></ul><p>All benchmarks were run on a 2021 M1 Pro MacBook Pro with 16GB of RAM.</p><h3>How to Run the Code</h3><p>If you’re interested in experimenting with the challenge yourself, here’s how you can run my solution:</p><ol><li><strong>Prepare the Input File:</strong><br>Place your input file in the testdata folder (or create a symlink to it).</li><li><strong>Run a Specific Version:</strong><br>Use the provided Makefile to run your desired version. For instance, to run v6, execute:</li></ol><pre>make run VERSION=v6</pre><ol><li><strong>Testing and Benchmarking:</strong><br>You can run tests and benchmarks with:</li></ol><pre>make test make bench VERSION=v6</pre><h3>Final Thoughts</h3><p>The One Billion Row Challenge pushed me to explore the depths of Go’s performance capabilities. My initial attempt in March–April 2024 didn’t meet my expectations, but the spark reignited at Gophercon 2024 set me on a path of relentless optimization. From refactoring parsing logic to harnessing concurrency and finally employing advanced compiler techniques like PGO, every step of the journey taught me invaluable lessons about performance tuning in Go.</p><p>I hope my story and the insights I’ve shared inspire you to tackle your own optimization challenges. Thank you for following along on my journey, and happy coding!</p><p>Keep an eye out for Go 1.24 — I’ve heard that with Go 1.24, <a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95">maps are touted to get a huge performance boost</a>! Once Go 1.24 is released, I plan to re-run my benchmarks to see how much further I can push the limits. Stay tuned for those updates</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96a97484ddf7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/my-journey-through-the-one-billion-row-challenge-in-go-96a97484ddf7">My Journey Through the One Billion Row Challenge in Go</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enhancements to Go Tooling in 1.24: go vet, go build, and More]]></title>
            <link>https://medium.com/technogise/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f9ef888395a</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sun, 09 Feb 2025 15:08:34 GMT</pubDate>
            <atom:updated>2026-04-01T10:21:10.485Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 brings significant improvements to its tooling, making development, debugging, and dependency management more efficient. This update enhances go vet, introduces JSON output for go build and go test, improves caching mechanisms, and refines authentication for private module fetches. Go 1.24 also introduces significant improvements to the <strong>compiler and linker</strong>, focusing on performance and debugging. These changes make Go programs compile faster and enable better debugging.</p><h3>1. Improved Static Analysis with go vet</h3><p>go vet now includes more robust checks, helping developers catch common issues before they reach production.</p><h3>New Test Analyser</h3><p>The new test analyser reports common mistakes in test declarations, such as:</p><ul><li>Malformed test, benchmark, or fuzz function names.</li><li>Incorrect function signatures.</li><li>Examples that reference non-existent identifiers.</li></ul><h4>Example: Catching a Malformed Test Name</h4><pre>package main<br><br>import &quot;testing&quot;<br><br>func BenchmarktestFunction(b *testing.B) { // Incorrect: should be BenchmarkTestFunction<br>    for i := 0; i &lt; b.N; i++ {<br>        _ = i * i<br>    }<br>}</pre><p>Running go vet ./... would flag this error, preventing incorrect benchmarks from silently failing.</p><h3>Enhanced printf Analyser</h3><p>go vet now detects cases where fmt.Printf is mistakenly used with a dynamic format string without arguments.</p><h4>Example:</h4><pre>package main<br><br>import &quot;fmt&quot;<br><br>func main() {<br>    s := &quot;Value: %d&quot;<br>    fmt.Printf(s) // Warning: %d expects an argument<br>}</pre><p>go vet will warn about this mistake and suggest using fmt.Print instead.</p><h3>2. Structured JSON Output for go build and go test</h3><p>To better integrate with CI/CD pipelines, go build and go test now support structured JSON output.</p><h3>Example: JSON Output for go build</h3><pre>go build -json ./...</pre><p>This produces structured logs that make it easier to analyse build failures programmatically.</p><h3>Example: JSON Output for go test</h3><pre>go test -json ./...</pre><p>This extends the JSON format to include both <strong>test results and build errors</strong>, making it easier to debug failing tests.</p><h3>3. Improved Caching for go run and go tool</h3><p>Executables created by go run and go tool are now cached, improving performance for repeated executions.</p><h3>Example: Caching in Action</h3><pre>go run myscript.go  # First run compiles and caches the binary</pre><p>Subsequent runs will execute faster since Go reuses the cached binary instead of recompiling it.</p><h3>4. go get Enhancements and Tool Tracking</h3><p>Go modules can now <strong>track executable dependencies</strong> using tool directives in go.mod, replacing the previous tools.go workaround.</p><h3>Example: Adding a Tool Directly to go.mod</h3><p>Instead of requiring a separate tools.go file, developers can now add tools directly to go.mod:</p><pre>tool golang.org/x/tools/cmd/stringer</pre><p>This ensures the tool is explicitly managed by Go modules, making dependency tracking more straightforward.</p><p>Alternatively, the -tool flag can be used:</p><pre>go get -tool golang.org/x/tools/cmd/stringer</pre><p>Additionally, go install tool allows for installing all tools tracked in go.mod:</p><pre>go install tool</pre><p>This streamlines environment setup and dependency management.</p><h3>5. Authentication for Private Module Fetches (GOAUTH)</h3><p>The new GOAUTH environment variable provides a flexible authentication mechanism for fetching private modules. See go help goauth for more information. This allows Go to use stored credentials for private repository access without requiring manual authentication prompts.</p><h3>6. Faster Compilation and Optimized Code Generation</h3><p>Go 1.24 includes optimizations that reduce <strong>compilation time</strong> and <strong>runtime overhead</strong>.</p><h3>Key Improvements:</h3><ul><li><strong>Better register allocation</strong>: The compiler now optimizes how registers are assigned, reducing redundant memory accesses.</li><li><strong>Faster function inlining</strong>: Improves execution speed by reducing function call overhead.</li><li><strong>More efficient stack frame layout</strong>: Reduces stack memory usage and improves function calls.</li></ul><h4>Example: Measuring Compilation Time Before and After Go 1.24</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/749/1*CeVhAKQJeR_z2BUGE_cPtw@2x.png" /></figure><h3>2. Improved Debugging with GNU Build ID and Mach-O UUID</h3><p>Go 1.24 now generates <strong>GNU build IDs</strong> (for Linux ELF binaries) and <strong>Mach-O UUIDs</strong> (for macOS binaries). These IDs make debugging and symbol management easier.</p><h3>Checking the Build ID on Linux</h3><pre>readelf -n myapp | grep &quot;Build ID&quot;</pre><h3>Checking the Mach-O UUID on macOS</h3><pre>otool -l myapp | grep &quot;UUID&quot;</pre><h3>Conclusion</h3><p>Go 1.24 significantly enhances its tooling, making development workflows more efficient and reliable. From improved static analysis and structured logging to better caching and authentication, these updates streamline development, testing, and deployment. Moreover, the Go 1.24 compiler and linker bring faster builds, smaller binaries, and better debugging support — ensuring Go remains efficient for modern application development.</p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><strong><em>Enhancements to Go Tooling in 1.24: </em></strong><em>go vet</em><strong><em>, </em></strong><em>go build</em><strong><em> and More</em></strong></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f9ef888395a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a">Enhancements to Go Tooling in 1.24: go vet, go build, and More</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Concurrency Testing in Go 1.24: Exploring testing/synctest]]></title>
            <link>https://medium.com/technogise/advanced-concurrency-testing-in-go-1-24-exploring-testing-synctest-0486f610cd82?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/0486f610cd82</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sun, 09 Feb 2025 15:07:48 GMT</pubDate>
            <atom:updated>2026-04-01T10:23:03.353Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces the new testing/synctest package, an experimental feature designed to improve testing for concurrent code. This package provides mechanisms to isolate and observe goroutines in a controlled environment, helping developers detect subtle race conditions, deadlocks, and concurrency issues that might otherwise go unnoticed.</p><h3>Why testing/synctest?</h3><p>Concurrency bugs can be notoriously difficult to detect and reproduce due to their non-deterministic nature. Traditional testing methods often fail to expose these issues reliably. The testing/synctest package addresses this challenge by introducing tools to:</p><ul><li><strong>Isolate goroutines</strong> to test them in a controlled environment.</li><li><strong>Manipulate time</strong> in concurrent tests to ensure predictable execution.</li><li><strong>Detect blocking conditions</strong> and deadlocks before they manifest in production.</li></ul><h3>Key Features of testing/synctest</h3><h3>1. Manipulating Time for Predictable Tests</h3><p>Traditional time-based tests rely on real-world timing, making them unreliable. synctest.Run ensures that <strong>time progresses predictably within a controlled test environment</strong>.</p><h4>Example: Ensuring Consistent Timing</h4><pre>package synctest<br><br>import (<br>  &quot;testing&quot;<br>  &quot;testing/synctest&quot;<br>  &quot;time&quot;<br>)<br>func TestTime3(t *testing.T) {<br>  synctest.Run(func() {<br>    before := time.Now()<br>    time.Sleep(10 * time.Second)<br>    after := time.Now()<br>    if d := after.Sub(before); d != 10*time.Second {<br>       t.Fatalf(&quot;took %v&quot;, d)<br>    } else {<br>       t.Logf(&quot;took %v&quot;, d)<br>    }<br>  })<br>}</pre><h3>2. Testing Concurrent Execution with synctest.Run</h3><p>synctest.Run enables controlled execution of concurrent code, ensuring goroutines do not behave unpredictably.</p><h4>Example: Ensuring Controlled Execution</h4><pre>package synctest<br><br>import (<br>  &quot;context&quot;<br>  &quot;sync/atomic&quot;<br>  &quot;testing&quot;<br>  &quot;testing/synctest&quot;<br>  &quot;time&quot;<br>)<br>func TestConcurrency2(t *testing.T) {<br>  synctest.Run(func() {<br>    ctx := context.Background()<br>    ctx, cancel := context.WithCancel(ctx)<br>    tick := time.NewTicker(time.Millisecond)<br>    var hits atomic.Int32<br>    go func() {<br>     defer tick.Stop()<br>     for {<br>        select {<br>            case &lt;-ctx.Done():<br>                 return<br>            case &lt;-tick.C:<br>                 hits.Add(1)<br>        }<br>     }<br>   }()<br>   time.Sleep(4 * time.Millisecond)<br>   cancel()<br>   got := int(hits.Load())<br>   if want := 3; got != want {<br>       t.Fatalf(&quot;got %v, want %v&quot;, got, want)<br>   }<br> })<br>}</pre><h3>Use Cases for testing/synctest</h3><ul><li><strong>Testing concurrent algorithms</strong>: Ensure correctness under various execution conditions.</li><li><strong>Detecting deadlocks early</strong>: Identify blocked goroutines before they impact production.</li><li><strong>Ensuring predictable time-based behaviour</strong>: Eliminate flakiness in time-dependent tests.</li></ul><h3>Conclusion</h3><p>The testing/synctest package in Go 1.24 provides powerful new tools for testing concurrent applications. By allowing controlled goroutine isolation, blocking detection, and time manipulation, this package makes it easier to identify and fix concurrency-related bugs.</p><p>Since testing/synctest is currently <strong>experimental</strong>, developers must enable it explicitly using:</p><pre>GOEXPERIMENT=synctest go test ./...</pre><p>Stay tuned for our next post, where we explore <a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><strong>enhancements to the Go toolchain in Go 1.24</strong></a><strong>.</strong></p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><strong><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></strong><em>testing/synctest</em></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0486f610cd82" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/advanced-concurrency-testing-in-go-1-24-exploring-testing-synctest-0486f610cd82">Advanced Concurrency Testing in Go 1.24: Exploring testing/synctest</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness & More]]></title>
            <link>https://medium.com/technogise/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b60374f8b8f</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sun, 09 Feb 2025 15:06:37 GMT</pubDate>
            <atom:updated>2026-04-01T10:23:15.075Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces significant improvements to its cryptographic capabilities, including support for post-quantum cryptography, new hashing and key derivation functions, and enhancements for <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.140-3.pdf">FIPS 140–3</a> compliance. These updates strengthen Go’s security posture and future-proof applications against emerging threats.</p><h3>Post-Quantum Cryptography: crypto/mlkem</h3><p>One of the most notable enhancements in Go 1.24 is the <strong>crypto/mlkem</strong> package, which provides <strong>ML-KEM-768 </strong>and <strong>ML-KEM-1024</strong> post-quantum key encapsulation mechanisms based on the <strong>Kyber</strong> algorithm — recently standardized in <a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.203.pdf"><strong>FIPS 203</strong></a>.</p><p>Below is an example demonstrating how to use these new features. The code defines a <strong>Person</strong> struct that stores a decapsulation key (dk) and a sharedSecret:</p><pre>type Person struct {<br> name         string // Name of the person.<br> dk           []byte // The person&#39;s decapsulation key. This is only set if the person calls GenerateKey.<br> sharedSecret []byte // The shared secret between the person and another person.<br>}</pre><p>It includes methods for <strong>generating a key</strong> (GenerateKey):</p><pre>func (p *Person) GenerateKey() ([]byte, error) {<br> // Generate a new key pair.<br> dk, err := mlkem.GenerateKey768()<br> if err != nil {<br>  return nil, err<br> }<br> // The decapsulation key is saved for later use.<br> p.dk = dk.Bytes()<br> // The encapsulation key returned to the caller.<br> return dk.EncapsulationKey().Bytes(), nil<br>}</pre><p><strong>Encapsulating</strong> that key to produce a ciphertext (Encapsulate):</p><pre>func (p *Person) Encapsulate(encapsulationKey []byte) ([]byte, error) {<br> // create a new encapsulation key from the bytes.<br> ek, err := mlkem.NewEncapsulationKey768(encapsulationKey)<br> if err != nil {<br>  log.Fatal(err)<br> }<br> // Encapsulate the key to generate the shared secret and the ciphertext.<br> sharedSecret, ciphertext := ek.Encapsulate()<br> // Save the shared secret for later use.<br> p.sharedSecret = sharedSecret<br> // Return the ciphertext to the caller.<br> return ciphertext, nil<br>}</pre><p>And <strong>decapsulating</strong> the ciphertext to retrieve the shared secret (Decapsulate):</p><pre>func (p *Person) Decapsulate(ciphertext []byte) error {<br> // Create a new decapsulation key from the bytes.<br> dk, err := mlkem.NewDecapsulationKey768(p.dk)<br> if err != nil {<br>  return err<br> }<br> // Decapsulate the ciphertext to generate the shared secret.<br> sharedSecret, err := dk.Decapsulate(ciphertext)<br> if err != nil {<br>  return err<br> }<br> // Save the shared secret for later use.<br> p.sharedSecret = sharedSecret<br><br> return nil<br>}</pre><p>The example then demonstrates using the shared secret with AES-GCM to <strong>encrypt</strong> and <strong>decrypt</strong> messages (Encrypt and Decrypt) by leveraging the sharedSecret created earlier:</p><pre>func (p *Person) Encrypt(plaintext string) (string, error) {<br> // Create a new AES block cipher with the shared secret.<br> block, err := aes.NewCipher(p.sharedSecret)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // Create a new Galois Counter Mode (GCM) block cipher.<br> gcm, err := cipher.NewGCM(block)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // A nonce should always be randomly generated for every encryption.<br> nonce := make([]byte, gcm.NonceSize())<br> // Read random bytes into the nonce.<br> _, err = io.ReadFull(rand.Reader, nonce)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // Encrypt the plaintext using the GCM block cipher.<br> ciphertext := gcm.Seal(nil, nonce, []byte(plaintext), nil)<br> // Return the ciphertext as a raw base64 encoded string.<br> return base64.RawStdEncoding.EncodeToString(append(nonce, ciphertext...)), nil<br>}<br><br>func (p *Person) Decrypt(ciphertext string) (string, error) {<br> // Create a new AES block cipher with the shared secret.<br> block, err := aes.NewCipher(p.sharedSecret)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // Create a new Galois Counter Mode (GCM) block cipher.<br> gcm, err := cipher.NewGCM(block)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // Decode the raw base64 encoded ciphertext.<br> cipherTextBytes, err := base64.RawStdEncoding.DecodeString(ciphertext)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // The nonce is the first nonceSize bytes of the ciphertext.<br> nonceSize := gcm.NonceSize()<br> // Extract the nonce and the ciphertext from the ciphertext bytes.<br> nonce, cipherTextBytes := cipherTextBytes[:nonceSize], cipherTextBytes[nonceSize:]<br> // Decrypt the ciphertext using the GCM block cipher.<br> plaintext, err := gcm.Open(nil, nonce, cipherTextBytes, nil)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> // Return the plaintext as a string.<br> return string(plaintext), nil<br>}</pre><h3>A Story of Secure Communication</h3><p>Imagine Alice and Bob, two individuals who want to securely exchange messages. They decide to use <strong>ML-KEM-768</strong> to establish a shared secret over an untrusted network.</p><h4>1. Alice Generates Her Key Pair</h4><p>Alice generates a <strong>decapsulation key</strong> (private key) and an <strong>encapsulation key</strong> (public key). She then shares her encapsulation key with Bob.</p><pre>alice := Person{name: &quot;Alice&quot;}<br>encapsulationKey, err := alice.GenerateKey()<br>if err != nil {<br>    log.Fatal(err)<br>}</pre><h4>2. Bob Uses the Key to Encrypt a Shared Secret</h4><p>Bob receives Alice’s <strong>encapsulation key</strong> and uses it to generate a <strong>shared secret</strong> along with an encrypted ciphertext.</p><pre>bob := Person{name: &quot;Bob&quot;}<br>ciphertext, err := bob.Encapsulate(encapsulationKey)<br>if err != nil {<br>    log.Fatal(err)<br>}</pre><h4>3. Alice Decapsulates the Shared Secret</h4><p>Alice takes the ciphertext from Bob and <strong>decapsulates</strong> it using her private key, retrieving the shared secret.</p><pre>err = alice.Decapsulate(ciphertext)<br>if err != nil {<br>    log.Fatal(err)<br>}</pre><h4>4. Encrypting &amp; Decrypting Messages</h4><p>Now that both Alice and Bob share the same secret, they can securely exchange encrypted messages.</p><pre>encrypted, err := alice.Encrypt(&quot;Hello, Bob!&quot;)<br>if err != nil {<br>    log.Fatal(err)<br>}<br>decrypted, err := bob.Decrypt(encrypted)<br>if err != nil {<br>    log.Fatal(err)<br>}<br>fmt.Printf(&quot;Decrypted message: %s\n&quot;, decrypted) // Output: Hello, Bob!</pre><p>This demonstrates how <strong>ML-KEM-768</strong> can be used for secure post-quantum key exchange.</p><h3>New Cryptographic Functions</h3><h3>1. crypto/hkdf: Key Derivation Function</h3><p>Go 1.24 introduces crypto/hkdf, implementing <strong>HMAC-based Extract-and-Expand Key Derivation Function (HKDF)</strong>, as defined in <a href="https://datatracker.ietf.org/doc/html/rfc5869">RFC 5869</a>.</p><pre>package main<br><br>import (<br> &quot;crypto/hkdf&quot;<br> &quot;crypto/rand&quot;<br> &quot;crypto/sha3&quot;<br> &quot;fmt&quot;<br> &quot;log&quot;<br>)<br><br>func main() {<br> // Underlying hash function for HMAC.<br> hash := sha3.New256<br> keyLen := hash().Size()<br><br> // Cryptographically secure master secret.<br> secret := make([]byte, 128)<br> if _, err := rand.Read(secret); err != nil {<br>  log.Fatalln(err)<br> }<br><br> // Recommended: hash-length random value.<br> salt := make([]byte, hash().Size())<br> if _, err := rand.Read(salt); err != nil {<br>  log.Fatalln(err)<br> }<br><br> // Non-secret context info, optional (can be nil).<br> info := &quot;seed for encryption&quot;<br> key1, err := hkdf.Key(hash, secret, salt, info, keyLen)<br> if err != nil {<br>  log.Fatalln(err)<br> }<br> fmt.Printf(&quot;Key 1: %x\n&quot;, key1) // Key 1: 525ee612c750d7d17be59087d15588a43a9a6f8fb3f4fb501e97a170e65a0318<br><br> // Another way to derive a key from the master secret. This approach of Extract + Expand is recommend if you want<br> // to reuse the extracted key with multiple Expand invocations and different context values.<br> psKey, err := hkdf.Extract(hash, secret, salt)<br> if err != nil {<br>  log.Fatalln(err)<br> }<br><br> key2, err := hkdf.Expand(hash, psKey, info, keyLen)<br> if err != nil {<br>  log.Fatalln(err)<br> }<br><br> fmt.Printf(&quot;Key 2: %x\n&quot;, key2) // Key 2: 525ee612c750d7d17be59087d15588a43a9a6f8fb3f4fb501e97a170e65a0318<br><br> fmt.Println(&quot;Keys are equal:&quot;, string(key1) == string(key2)) // Keys are equal: true<br>}</pre><h3>2. crypto/pbkdf2: Password-Based Key Derivation</h3><p>PBKDF2 (Password-Based Key Derivation Function 2) is now available as crypto/pbkdf2, based on <a href="https://datatracker.ietf.org/doc/html/rfc8018">RFC 8018</a>.</p><pre>package main<br><br>import (<br> &quot;crypto/pbkdf2&quot;<br> &quot;crypto/rand&quot;<br> &quot;crypto/sha3&quot;<br> &quot;fmt&quot;<br> &quot;log&quot;<br>)<br><br>func main() {<br> hash := sha3.New256<br> keyLen := hash().Size()<br><br> salt := make([]byte, 16)<br> if _, err := rand.Read(salt); err != nil {<br>  log.Fatalln(err)<br> }<br><br> key, err := pbkdf2.Key(hash, &quot;super-secure-password&quot;, []byte(&quot;salt&quot;), 4096, keyLen)<br> if err != nil {<br>  log.Fatalln(err)<br> }<br><br> fmt.Printf(&quot;Derived key: %x\n&quot;, key) // Derived key: 895e5f5f70e0f8ff9ab68684480532fed7181c450a02124233c21b5f76c995af<br>}</pre><h3>3. crypto/sha3: SHA-3 Hashing Support</h3><p>Go 1.24 adds a built-in crypto/sha3 package, implementing <strong>SHA-3 and extendable-output functions (XOFs)</strong> as defined in <a href="https://nvlpubs.nist.gov/nistpubs/fips/nist.fips.202.pdf">FIPS 202</a>.</p><pre>package main<br><br>import (<br> &quot;crypto/sha3&quot;<br> &quot;fmt&quot;<br>)<br><br>func main() {<br> hash := sha3.Sum256([]byte(&quot;Hello, World!&quot;))<br> fmt.Printf(&quot;SHA3-256: %x\n&quot;, hash) // SHA3-256: 1af17a664e3fa8e419b8ba05c2a173169df76162a5a286e0c405b460d478f7ef<br>}</pre><h3>FIPS 140–3 Compliance in Go 1.24</h3><p><a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.140-3.pdf">FIPS 140–3</a> (Federal Information Processing Standard) compliance is a requirement for cryptographic modules used in government and regulated industries. Go 1.24 introduces a <strong>FIPS-compliant cryptographic module</strong>, which can be enabled via the GOFIPS140 environment variable.</p><pre>export GOFIPS140=1</pre><p>When enabled, Go will automatically select <strong>FIPS-approved cryptographic algorithms</strong> for secure communication.</p><h3>Conclusion</h3><p>The cryptographic enhancements in Go 1.24 provide <strong>quantum-resistant security, improved key derivation methods, and </strong><a href="https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.140-3.pdf"><strong>FIPS 140–3</strong></a><strong> compliance</strong>. These features make Go a stronger choice for building secure applications in an evolving cryptographic landscape.</p><p>Stay tuned for the next post, where we explore <a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><strong>the experimental </strong></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82">testing/synctest<strong> package for advanced concurrency testing</strong></a><strong>.</strong></p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><strong><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></strong></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b60374f8b8f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f">Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Memory Efficiency in Go 1.24: Introducing the weakPackage]]></title>
            <link>https://medium.com/technogise/memory-efficiency-in-go-1-24-introducing-the-weakpackage-91635691d53f?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/91635691d53f</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 13:36:29 GMT</pubDate>
            <atom:updated>2026-04-01T10:20:24.511Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Go 1.24</strong> introduces the new weak package, bringing <strong>weak pointers</strong> to the Go ecosystem. This feature enables developers to create memory-efficient data structures that do not prevent objects from being garbage-collected, making it particularly useful for caching, canonicalization, and managing references to large objects.</p><h3>What Are Weak Pointers?</h3><p>Weak pointers are references to objects that do not prevent those objects from being garbage-collected. If an object is only reachable through weak references, it will be eligible for garbage collection.</p><p>Before <strong>Go 1.24</strong>, developers had to implement workarounds such as manually managing object lifetimes using maps with runtime.SetFinalizer. The weak package simplifies this by providing a built-in, efficient mechanism.</p><h3>Using Weak Pointers in Go 1.24</h3><h3>Basic Example</h3><pre>package main<br><br>import (<br>  &quot;fmt&quot;<br>  &quot;runtime&quot;<br>  &quot;weak&quot;<br>)<br><br>type Data struct {<br>  value string<br>}<br><br>func main() {<br>  wp := weak.Make(&amp;Data{value: &quot;Temporary Data&quot;})<br><br>  fmt.Println(&quot;Weak Pointer Value:&quot;, wp.Value())<br><br>  runtime.GC()                                // Trigger garbage collection<br>  fmt.Println(&quot;After GC, Value:&quot;, wp.Value()) // Likely nil if GC has run<br>}</pre><h3>Key Features of the weak Package</h3><ul><li><strong>Automatic Clean-up</strong>: Objects referenced only by weak pointers can be garbage collected.</li><li><strong>Efficient Memory Use</strong>: Helps reduce memory pressure in caching scenarios.</li><li><strong>Safe Retrieval</strong>: Provides methods to check if the referenced object is still available.</li></ul><h3>Use Cases for Weak Pointers</h3><h3>1. Implementing Efficient Caches</h3><pre>package main<br><br>import (<br> &quot;fmt&quot;<br> &quot;runtime&quot;<br> &quot;weak&quot;<br>)<br><br>type Cache struct {<br>  data map[string]weak.Pointer[Data]<br>}<br><br>type Data struct {<br>  value string<br>}<br><br>func (c *Cache) Get(key string) *Data {<br>  if ptr, ok := c.data[key]; ok {<br>    return ptr.Value()<br>  }<br>  return nil<br>}<br><br>func main() {<br>  cache := &amp;Cache{data: make(map[string]weak.Pointer[Data])}<br>  cache.data[&quot;key&quot;] = weak.Make(&amp;Data{value: &quot;Cached Value&quot;})<br><br>  fmt.Println(&quot;Cache hit:&quot;, cache.Get(&quot;key&quot;))<br>  runtime.GC()<br>  fmt.Println(&quot;After GC, Cache hit:&quot;, cache.Get(&quot;key&quot;))<br>}</pre><h3>2. Managing Large Objects</h3><p>Applications dealing with large data structures (e.g., images, parsed files) can store weak references to avoid unnecessary memory retention.</p><h3>3. Canonicalization Maps</h3><p>When a system frequently loads identical values, weak pointers can help manage deduplicated instances efficiently.</p><h3>Comparison: Weak Pointers vs. Strong References</h3><pre>|    Feature      |  Strong Reference (*T) |  Weak Pointer (weak.Ptr[T]) |<br>|-----------------|------------------------|-----------------------------|<br>| Prevents GC     | Yes                    | No                          |<br>| Access Speed    | Fast                   | Slightly slower             |<br>| Ideal Use Case  | Persistent data        | Temporary, cache-related    |</pre><p>The weak package in <strong>Go 1.24</strong> enables more efficient memory management, helping developers implement better caching, canonicalization, and resource-sensitive applications. By reducing memory pressure while still allowing access to objects when needed, <strong>weak pointers</strong> make Go’s memory model more flexible and robust.</p><p>Stay tuned for the next article, where we explore the <a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><strong>new cryptographic enhancements in Go 1.24, including post-quantum cryptography support</strong></a><strong>.</strong></p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><strong><em>Memory Efficiency in Go 1.24: Introducing the </em></strong><em>weak</em><strong><em> package</em></strong></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91635691d53f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/memory-efficiency-in-go-1-24-introducing-the-weakpackage-91635691d53f">Memory Efficiency in Go 1.24: Introducing the weakPackage</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improved Finalization in Go 1.24: Introducing runtime.AddCleanup]]></title>
            <link>https://medium.com/technogise/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2f7a43831c2</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 13:36:15 GMT</pubDate>
            <atom:updated>2026-04-01T10:20:36.688Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces a significant improvement in how Go handles finalization and resource clean-up with the new runtime.AddCleanup function. This new mechanism provides a more efficient and flexible way to perform clean-up actions compared to the traditional runtime.SetFinalizer.</p><h3>Why runtime.AddCleanup?</h3><p>Finalizers in Go are used to run clean-up code when an object becomes unreachable, helping to release system resources such as file handles and network connections. However, runtime.SetFinalizer has several limitations:</p><ul><li><strong>Unpredictable Execution</strong>: The execution of finalizers depends on garbage collection, which is non-deterministic.</li><li><strong>Risk of Memory Leaks</strong>: Objects with finalizers may be kept alive longer than necessary.</li><li><strong>Difficulty Handling Cyclic References</strong>: When objects reference each other, finalization may not trigger as expected.</li></ul><p>To address these issues, Go 1.24 introduces runtime.AddCleanup, offering a more structured and predictable approach to resource clean-up.</p><h3>Using runtime.AddCleanup</h3><h3>Basic Example</h3><p>Here’s how runtime.AddCleanup can be used to register clean-up functions:</p><pre>package main<br><br>import (<br>  &quot;database/sql&quot;<br>  &quot;fmt&quot;<br>  &quot;runtime&quot;<br><br>  &quot;github.com/DATA-DOG/go-sqlmock&quot;<br>)<br><br>type Resource struct {<br>  db *sql.DB<br>}<br><br>func NewResource() *Resource {<br>  db, _, _ := sqlmock.New()<br>  res := &amp;Resource{db: db}<br><br>  runtime.AddCleanup(res, func(db *sql.DB) {<br>    fmt.Println(&quot;Closing DB connection&quot;)<br>    _ = db.Close()<br>  }, res.db)<br><br>  return res<br>}<br><br>func main() {<br>  res := NewResource()<br>  _ = res<br>  res = nil    // Drop reference to allow cleanup<br>  runtime.GC() // Force garbage collection for demonstration<br>}</pre><h3>Key Advantages</h3><ul><li><strong>Multiple Clean-up Functions</strong>: Unlike runtime.SetFinalizer, multiple clean-up functions can be attached to a single object.</li><li><strong>Handles Cyclic References</strong>: Works better in cases where objects form reference cycles.</li><li><strong>Does Not Delay Object Deallocation</strong>: Clean-up is handled more efficiently without prolonging the object’s lifetime unnecessarily.</li></ul><h3>Comparison with runtime.SetFinalizer</h3><pre>|      Feature      |               runtime.SetFinalizer             |              runtime.AddCleanup           |<br>|-------------------|------------------------------------------------|-------------------------------------------|<br>| Execution Timing  | Non-deterministic, tied to GC More predictable | Multiple Cleanups Not supported Supported |<br>| Handles Cycles    | No                                             | Yes                                       |<br>| Memory Efficiency | Can delay object collection                    | More efficient                            |</pre><h3>Use Cases for runtime.AddCleanup</h3><ul><li><strong>Managing File and Network Handles</strong>: Ensuring files and connections are closed properly.</li><li><strong>Preventing Memory Leaks</strong>: Efficient clean-up of in-memory caches and temporary objects.</li><li><strong>More Reliable Finalization</strong>: Providing a structured approach to cleaning up resources.</li></ul><h3>Conclusion</h3><p>The introduction of runtime.AddCleanup in Go 1.24 enhances the way finalization works, addressing key limitations of runtime.SetFinalizer. It provides a more predictable, flexible, and efficient way to manage resource clean-up.</p><p>Stay tuned for the next post, where we <a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><strong>explore the new </strong></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f">weak<strong> package and how it enables weak pointers for more memory-efficient applications</strong></a>.</p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><strong><em>Improved Finalization in Go 1.24: Introducing </em></strong><em>runtime.AddCleanup</em></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2f7a43831c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2">Improved Finalization in Go 1.24: Introducing runtime.AddCleanup</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secure Filesystem Access in Go 1.24: Introducing os.Root]]></title>
            <link>https://medium.com/technogise/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/dcb031732516</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[go]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 13:36:00 GMT</pubDate>
            <atom:updated>2026-04-01T10:20:47.005Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces the os.Root type, a new mechanism to improve filesystem security by providing <strong>directory-limited file access</strong>. This feature prevents accidental or malicious access to files outside a specified directory, making it particularly useful for sandboxed environments, containerized applications, and security-sensitive operations.</p><h3>Why os.Root?</h3><p>Traditionally, Go’s os package allows unrestricted file access, which can be problematic when handling untrusted inputs. os.Root ensures that all filesystem operations are confined to a specific directory, mitigating the risk of directory traversal vulnerabilities.</p><h3>Using os.Root for Secure File Access</h3><h3>Basic Example</h3><p>The following example demonstrates how to use os.Root to restrict file operations to a designated directory:</p><pre>package main<br><br>import (<br>    &quot;fmt&quot;<br>    &quot;os&quot;<br>)<br>func main() {<br>    root, err := os.OpenRoot(&quot;/safe-directory&quot;)<br>    if err != nil {<br>        panic(err)<br>    }<br>    defer root.Close()<br>    file, err := root.Create(&quot;example.txt&quot;)<br>    if err != nil {<br>        panic(err)<br>    }<br>    defer file.Close()<br>    _, err = file.WriteString(&quot;Secure content\n&quot;)<br>    if err != nil {<br>        panic(err)<br>    }<br>    fmt.Println(&quot;File written securely inside /safe-directory&quot;)<br>}</pre><p>In this example:</p><ul><li>os.OpenRoot(&quot;/safe-directory&quot;) creates a filesystem root confined to /safe-directory.</li><li>All file operations (Create, Open, Mkdir, Stat) are now <strong>restricted</strong> within this directory.</li><li>Any attempt to access files <strong>outside</strong> /safe-directory will result in an error.</li></ul><h3>Comparison with Traditional os Package Functions</h3><pre><br>|   Operation    |      Traditional os        |       Secure os.Root       |<br>|----------------|----------------------------|----------------------------|<br>| Open a file    |  os.Open(&quot;/file.txt&quot;)      |  root.Open(&quot;file.txt&quot;)     |<br>| Create a file  |  os.Create(&quot;/file.txt&quot;)    |  root.Create(&quot;file.txt&quot;)   |<br>| Read a file    |  os.ReadFile(&quot;/file.txt&quot;)  |  root.ReadFile(&quot;file.txt&quot;) |</pre><p>With os.Root, paths <strong>cannot escape</strong> the designated directory, preventing directory traversal attacks.</p><h3>Use Cases for os.Root</h3><ul><li><strong>Containerized applications</strong>: Prevent unintended access outside container-bound directories.</li><li><strong>Web servers handling user uploads</strong>: Securely store files within a controlled directory.</li><li><strong>CLI tools processing files</strong>: Restrict file access to predefined locations.</li><li><strong>Embedded systems</strong>: Limit filesystem operations to critical directories.</li></ul><h3>Handling Symbolic Links</h3><p>os.Root ensures that symbolic links pointing outside the root directory <strong>cannot be followed</strong>, providing an additional layer of security.</p><h3>Conclusion</h3><p>The introduction of os.Root in Go 1.24 provides a much-needed mechanism for <strong>secure, directory-limited filesystem access</strong>. By leveraging this feature, developers can build more secure and resilient applications that prevent unintended file access.</p><p>Stay tuned for the next article, where we explore <a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><strong>improved finalizers with </strong></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2">runtime.AddCleanup <strong>and how they enhance garbage collection efficiency</strong></a>.</p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><strong><em>Secure Filesystem Access in Go 1.24: Introducing</em></strong><em> </em><em>os.Root</em></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dcb031732516" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516">Secure Filesystem Access in Go 1.24: Introducing os.Root</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performance Optimizations in Go 1.24: Swiss Table Maps and More]]></title>
            <link>https://medium.com/technogise/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2681f7e5e95</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[swiss-table]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[maps]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 05:15:31 GMT</pubDate>
            <atom:updated>2026-04-01T10:20:56.701Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces significant performance optimizations, particularly in the way maps are handled. One of the standout features is the introduction of <strong>Swiss Table-based maps</strong>, which improve lookup and insertion performance. Additionally, Go 1.24 brings several other runtime and memory optimizations that make Go applications faster and more efficient.</p><h3>Swiss Table Maps: A Game-Changer</h3><h3>What Are Swiss Tables?</h3><p>Swiss Tables are a modern hash table implementation that optimizes memory layout and lookup performance by reducing collisions and improving cache locality. Originally introduced by Google for high-performance applications, this approach now powers Go’s built-in map implementation.</p><h3>Performance Gains</h3><p>Swiss Tables in Go 1.24 provide:</p><ul><li><strong>Faster lookups</strong>: Optimized probing reduces the number of cache misses.</li><li><strong>Better memory efficiency</strong>: More compact storage leads to reduced memory footprint.</li><li><strong>Improved insertions and deletions</strong>: Less overhead when modifying maps.</li></ul><h3>Benchmarking Swiss Tables</h3><p>Let’s compare the old vs. new map performance using Go’s benchmarking framework.</p><pre>package main<br><br>import (<br>  &quot;fmt&quot;<br>  &quot;io&quot;<br>  &quot;testing&quot;<br>)<br><br>func BenchmarkMapInsert(b *testing.B) {<br>  m := make(map[int]int)<br>  b.ResetTimer()<br>  for i := 0; i &lt; b.N; i++ {<br>    m[i] = i<br>  }<br>}<br><br>func BenchmarkMapLookup(b *testing.B) {<br>  m := make(map[int]int)<br>  for i := 0; i &lt; 1_000_000; i++ {<br>    m[i] = i<br>  }<br>  var n int<br>  b.ResetTimer()<br>  for i := 0; i &lt; b.N; i++ {<br>    n = m[i%1_000_000]<br>  }<br>  _, _ = fmt.Fprintln(io.Discard, n)<br>}</pre><p>Benchmarks comparing <strong>Go 1.23</strong> and <strong>Go 1.24</strong> on an <strong>Apple M1 Pro </strong>show significant performance improvements:</p><h4>Execution Time (sec/op)</h4><pre>│ Go 1.23      │ Go 1.24 (RC2)        │ Improvement                       |<br>|--------------|----------------------|---------------------|-------------|<br>| MapInsert-10 │ 137.10n ± 4%         │ 93.70n ± 2%         │ -31.65%     |<br>| MapLookup-10 │  41.17n ± 2%         │ 32.36n ± 5%         │ -21.40%.    |</pre><p>These benchmarks confirm that Swiss Table maps in <strong>Go 1.24</strong> lead to significant reductions in execution time while maintaining similar memory and allocation efficiency.</p><h3>Runtime and Memory Optimizations</h3><h3>1. Improved Garbage Collection (GC)</h3><p>Go 1.24 optimizes how GC manages memory allocation for small objects, reducing GC pauses and improving overall application responsiveness.</p><h3>2. New Internal Mutex Implementation</h3><p>A refined mutex implementation improves contention resolution, leading to better concurrency performance, especially in applications with high lock contention.</p><h3>3. Enhanced sync.Map Performance</h3><p>Modifications to sync.Map make disjoint key accesses significantly faster, reducing contention in concurrent workloads.</p><h3>How to Enable/Disable Swiss Table Maps</h3><p>By default, Swiss Table maps are enabled in Go 1.24, but developers can opt out using:</p><pre>GOEXPERIMENT=noswissmap go build</pre><h3>Conclusion</h3><p>Swiss Table maps and runtime optimizations in Go 1.24 lead to measurable performance improvements, making Go applications faster and more memory-efficient.</p><p>Stay tuned for the next post, where we explore the <a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><strong>new </strong></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516">os.Root<strong> type and its implications for secure filesystem access</strong></a>.</p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><strong><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></strong></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2681f7e5e95" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95">Performance Optimizations in Go 1.24: Swiss Table Maps and More</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Generic Type Aliases in Go 1.24]]></title>
            <link>https://medium.com/technogise/exploring-generic-type-aliases-in-go-1-24-a85aade91970?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/a85aade91970</guid>
            <category><![CDATA[generics]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 05:14:43 GMT</pubDate>
            <atom:updated>2026-04-02T11:25:37.833Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 introduces full support for <strong>generic type aliases</strong>, an enhancement that simplifies the use of generics by allowing type aliases to be parameterized like defined types. This update reduces code redundancy, enhances readability, and improves maintainability.</p><h3>What Are Generic Type Aliases?</h3><p>Before Go 1.24, type aliases were limited in their ability to support generics. With this update, developers can define type aliases with type parameters, making it easier to reuse and compose generic types.</p><h3>Basic Example</h3><pre>package main<br><br>import &quot;fmt&quot;<br>// Container is a struct that holds a value of any type<br>type Container[T any] struct {<br>   Value T<br>}<br>// Box is an alias for Container<br>type Box[T any] = Container[T]<br>func main() {<br>   intBox := Box[int]{Value: 42}<br>   strBox := Box[string]{Value: &quot;Hello&quot;}<br>   fmt.Println(intBox.Value) // 42<br>   fmt.Println(strBox.Value) // Hello<br>}</pre><p>Here, Box[T] is an alias for Container[T], allowing seamless reuse without redefining the struct.</p><h3>Why Generic Type Aliases Matter</h3><h3>1. Reducing Code Duplication</h3><p>Previously, developers had to create wrapper types or repeat generic constraints to achieve aliasing functionality. With Go 1.24, this is streamlined, reducing duplication and potential maintenance issues.</p><h3>2. Improving Readability</h3><p>Generic type aliases enable clearer abstractions, making code more intuitive.</p><pre>package main<br><br>import &quot;fmt&quot;<br>// List is a generic type that represents a slice of elements of any type.<br>type List[T any] = []T<br>// Sum calculates the sum of all elements in a list of numbers.<br>func Sum[T int | float64](nums List[T]) T {<br>     var total T<br>     for _, n := range nums {<br>          total += n<br>    }<br>    return total<br>}<br>func main() {<br>    fmt.Println(Sum([]int{1, 2, 3}))      // Output: 6<br>    fmt.Println(Sum([]float64{1.1, 2.2})) // Output: 3.3<br>}</pre><p>By aliasing []T as List[T], we make the function more expressive without introducing new struct definitions.</p><h3>3. Enabling Cleaner API Definitions</h3><p>This feature is particularly useful in API design, where parameterized aliases improve expressiveness while keeping type definitions minimal.</p><pre>type HandlerFunc[T any] = func(T) error<br>type StringHandler = HandlerFunc[string]<br>type IntHandler = HandlerFunc[int]</pre><p>This makes API contracts more readable and maintainable.</p><h3>Benchmarks &amp; Performance Considerations</h3><p>Generic type aliases do not introduce runtime overhead because they are resolved at compile time. Performance remains consistent with directly using the underlying type.</p><h3>Backward Compatibility &amp; Transition</h3><p>Developers using GOEXPERIMENT=noaliastypeparams can disable this feature temporarily, but it will be fully integrated in Go 1.25 without an option to disable it.</p><h3>Conclusion</h3><p>Generic type aliases in Go 1.24 improve code maintainability, readability, and reuse. By leveraging them effectively, developers can write cleaner and more expressive Go code.</p><p>Stay tuned for our next post, where we explore the <a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><strong>performance optimizations in Go 1.24, including Swiss Table-based maps</strong></a>.</p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><a href="https://medium.com/@ajitem/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77"><em>Introduction to Go 1.24: What’s New and Why It Matters</em></a></li><li><strong><em>Exploring Generic Type Aliases in Go 1.24</em></strong></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a85aade91970" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/exploring-generic-type-aliases-in-go-1-24-a85aade91970">Exploring Generic Type Aliases in Go 1.24</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Go 1.24: What’s New and Why It Matters]]></title>
            <link>https://medium.com/technogise/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77?source=rss-33fcdacba2f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd6fa0bc3b77</guid>
            <category><![CDATA[go]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Ajitem Sahasrabuddhe]]></dc:creator>
            <pubDate>Fri, 07 Feb 2025 05:14:10 GMT</pubDate>
            <atom:updated>2025-03-03T07:26:01.608Z</atom:updated>
            <content:encoded><![CDATA[<p>Go 1.24 is set to be released in February 2025, bringing with it a host of improvements in <strong>performance, tooling, language features, cryptography, and runtime enhancements</strong>. This blog post serves as an introduction to the key updates, providing an overview before diving into specific changes in future posts.</p><h3>Why Upgrade to Go 1.24?</h3><p>With Go 1.24, developers can expect:</p><ul><li><strong>Performance improvements</strong>: Swiss table-based maps and optimized runtime internals lead to faster execution.</li><li><strong>Better tooling</strong>: JSON support for go build and go test, new dependency tracking with tool directives, and enhancements to go vet.</li><li><strong>Security upgrades</strong>: New cryptographic packages (crypto/mlkem, crypto/hkdf, crypto/pbkdf2, crypto/sha3) and FIPS 140-3 compliance.</li><li><strong>Language enhancements</strong>: Full support for <strong>generic type aliases</strong>, reducing redundancy in complex codebases.</li><li><strong>Testing enhancements</strong>: The new testing.B.Loop function simplifies benchmark iteration, and the testing/synctest package helps test concurrent programs more effectively.</li><li><strong>Filesystem security improvements</strong>: The os.Root type enables directory-limited filesystem access, enhancing security in containerized and sandboxed environments.</li></ul><h3>1. Language Enhancements</h3><h3>Generic Type Aliases</h3><p>Go 1.24 now fully supports <strong>generic type aliases</strong>, allowing type aliases to be parameterized, similar to defined types. This improves code reusability and simplifies generic programming.</p><h4>Example: Generic Type Aliases</h4><pre>type List[T any] = []T</pre><p>Previously, generics required explicit definitions, but now type aliases can be used directly, making code more maintainable.</p><h3>2. Performance Improvements</h3><p>Go 1.24 introduces <strong>Swiss Tables for map operations</strong>, leading to significant performance gains. With this, we should see measurable improvements, especially for large datasets.</p><h3>Faster Compilation and Optimized Code Generation</h3><ul><li><strong>Better register allocation</strong>: Reduces redundant memory accesses.</li><li><strong>Faster function inlining</strong>: Reduces function call overhead.</li><li><strong>More efficient stack frame layout</strong>: Improves function calls and memory usage.</li></ul><h4>Measuring Compilation Time Improvements</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*T1dsxT9I6NpQAcE72ZuPKw@2x.png" /></figure><h3>3. Security and Cryptography Updates</h3><p>Go 1.24 strengthens security with:</p><ul><li><strong>New </strong><strong>crypto/mlkem package</strong>: Implements post-quantum cryptography standards (ML-KEM-768 and ML-KEM-1024).</li><li><strong>New hashing and key derivation functions</strong>: crypto/hkdf, crypto/pbkdf2, crypto/sha3.</li><li><strong>FIPS 140–3 compliance</strong>: New GOFIPS140 environment variable ensures cryptographic compliance.</li></ul><h3>4. Testing Improvements</h3><h3>New testing.B.Loop for Benchmarks</h3><p>The traditional b.N loop can be error-prone due to several reasons:</p><ul><li><strong>Incorrect Use of </strong><strong>b.N in Setup Code</strong>: Expensive setup operations inside for i := 0; i &lt; b.N; i++ can skew benchmark results.</li><li><strong>Loop Iterations Not Scaling Well</strong>: Large b.N values may distort results.</li><li><strong>Optimization by the Go Compiler</strong>: The compiler may optimize away computations inside b.N loops.</li><li><strong>Inconsistent Iteration Control</strong>: b.N dynamically increases, which can affect consistency.</li></ul><h3>Why b.Loop() is Better</h3><p>According to <a href="https://github.com/golang/go/issues/61515"><strong>Go issue #61515</strong></a>, b.Loop() provides:</p><ul><li>Automatic iteration control</li><li>Proper setup and clean-up handling</li><li>More predictable benchmarking</li></ul><h4>Example:</h4><pre>func BenchmarkMyFunction(b *testing.B) {<br>    for b.Loop() {<br>        MyFunction()<br>    }<br>}</pre><h3>testing/synctest for Concurrent Testing</h3><p>The synctest.Run function enables better testing of concurrent code:</p><pre>package main<br>import (<br>    &quot;testing&quot;<br>    &quot;testing/synctest&quot;<br>)<br>func TestConcurrent(t *testing.T) {<br>    synctest.Run(t, func() {<br>        go someConcurrentFunction()<br>        synctest.Wait()<br>    })<br>}</pre><h3>5. Tooling Enhancements</h3><h3>JSON Support for go build and go test</h3><p>The -json flag now provides structured output, making it easier to integrate with CI/CD pipelines and debugging tools.</p><pre>go build -json ./...</pre><pre>go test -json ./...</pre><h3>New tool Directives for Dependency Management</h3><p>Go modules can now track executable dependencies directly using tool directives in go.mod, eliminating the need for tools.go files.</p><pre>go get -tool golang.org/x/tools/cmd/stringer</pre><p>Alternatively, tools can be directly added to go.mod:</p><pre>tool golang.org/x/tools/cmd/stringer</pre><h3>6. Garbage Collection Enhancements</h3><p>Go 1.24 improves garbage collection (GC) performance by lowering GC overhead, optimizing large object handling, and ensuring more predictable latency. These optimizations result in better memory management, reducing the impact of GC pauses in high-performance applications.</p><h3>Final Thoughts</h3><p>Go 1.24 is a <strong>major step forward</strong>, providing performance boosts, security hardening, and developer-friendly enhancements. Over the course of this series, we’ll explore these features in-depth, providing <strong>code examples, performance benchmarks, and migration tips</strong>.</p><p>Stay tuned for the next post, where we dive deep into <a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><strong>Go 1.24’s generic type aliases and how they simplify code maintenance</strong></a><strong>.</strong></p><p><em>This post is a part of a series, where we delve deeper into Go 1.24. Each entry builds upon the last. Be sure to explore the entire series to get the full picture.</em></p><ol><li><strong><em>Introduction to Go 1.24: What’s New and Why It Matters</em></strong></li><li><a href="https://medium.com/@ajitem/exploring-generic-type-aliases-in-go-1-24-a85aade91970"><em>Exploring Generic Type Aliases in Go 1.24</em></a></li><li><a href="https://medium.com/@ajitem/performance-optimizations-in-go-1-24-swiss-table-maps-and-more-b2681f7e5e95"><em>Performance Optimizations in Go 1.24: Swiss Table Maps and More</em></a></li><li><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>Secure Filesystem Access in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/secure-filesystem-access-in-go-1-24-introducing-os-root-dcb031732516"><em>os.Root</em></a></li><li><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>Improved Finalization in Go 1.24: Introducing </em></a><a href="https://medium.com/@ajitem/improved-finalization-in-go-1-24-introducing-runtime-addcleanup-e2f7a43831c2"><em>runtime.AddCleanup</em></a></li><li><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>Memory Efficiency in Go 1.24: Introducing the </em></a><a href="https://medium.com/@ajitem/memory-efficiency-in-go-1-24-introducing-the-weak-package-91635691d53f"><em>weak package</em></a></li><li><a href="https://medium.com/@ajitem/cryptographic-enhancements-in-go-1-24-post-quantum-readiness-more-5b60374f8b8f"><em>Cryptographic Enhancements in Go 1.24: Post-Quantum Readiness &amp; More</em></a></li><li><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>Advanced Concurrency Testing in Go: Exploring the experimental </em></a><a href="https://medium.com/@ajitem/advanced-concurrency-testing-in-go-1-24-exploring-the-experimental-testing-synctest-0486f610cd82"><em>testing/synctest</em></a></li><li><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>Enhancements to Go Tooling in 1.24: </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go vet, </em></a><a href="https://medium.com/@ajitem/enhancements-to-go-tooling-in-1-24-go-vet-go-build-and-more-6f9ef888395a"><em>go build and More</em></a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd6fa0bc3b77" width="1" height="1" alt=""><hr><p><a href="https://medium.com/technogise/introduction-to-go-1-24-whats-new-and-why-it-matters-bd6fa0bc3b77">Introduction to Go 1.24: What’s New and Why It Matters</a> was originally published in <a href="https://medium.com/technogise">Technogise</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>