Teiva Harsanyi Profile picture
Mar 15 11 tweets 4 min read
🧵 Go 1.18 got released 🥳. Outside of generics, five new features we should be aware of.
tip.golang.org/doc/go1.18 #golang
👇
1. Fuzz testing

Fuzzing is about passing random data to functions in an attempt to find vulnerabilities or crash-causing inputs.

Imagine the following scenario where we have to implement a custom function to test whether a string starts with a prefix: Image
Sometimes, it can be quite cumbersome trying to think by ourselves about all the different cases to be tested. Fuzzing is here to help us with that: Image
We wrote a custom fuzz test with a given seed corpus (basically, a guide for the fuzz engine). Then, we can run the test:

$ go test -fuzz FuzzHasPrefix
--- FAIL: FuzzHasPrefix (0.04s)
testing.go:1349: panic: runtime error: slice bounds out of range [:2] with length 1
The engine has found a vulnerability that led the function to panic. It has created a unique file in /testdata containing the inputs that lead to a failure:

string("0") // s
string("00") // prefix

More info here: go.dev/doc/tutorial/f…
2. GC & Pacer

The pacer is the algorithm used to determine when to start a new GC cycle. It has been redesigned to include not only heap data but also other sources such as the stack.

As a result, it may, in some cases, help the GC to be more predictable.
When using Go 1.18, let's keep an eye on the GC behavior of our application and make sure everything is still running smoothly. As always, tweaking GOGC remains the only available option to tune the GC.

The new design: github.com/golang/proposa…
3. Cut

In the strings and bytes packages, a new Cut function is now available.

Given a string (or a []byte) and a prefix, it returns:
- The text before the separator
- The text after the separator
- Whether the separator was found Image
4. Try lock

sync.Mutex and sync.RWMutex are given new methods for trying to acquire a lock and report whether it succeeded:
- sync.Mutex => TryLock()
- sync.RWMutex => TryLock() and TryRLock()

Compared to Lock() and RLock(), these functions are not blocking Image
5. Workspace mode

In an attempt to provide better support for monorepos, Go 1.18 introduces a workspace mode.

Projects that rely on the workspace mode will have a new go.work file referencing the modules of the project: Image
For more information:
$ go work

Or the Github issue: github.com/golang/go/issu…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Teiva Harsanyi

Teiva Harsanyi Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(