Go

Go

Made by DeepSource
Missing an optimization opportunity when indexing maps by byte slices SCC-SA6001
Performance
Major
Autofix

Map keys must be comparable, which precludes the use of byte slices. This usually leads to using string keys and converting byte slices to strings.

Using regexp.Match or related in a loop SCC-SA6000
Performance
Major

Compile parses a regular expression and returns, if successful, a Regexp object that can be used to match against text.

When matching in a loop, use regexp.Compile instead.

time.Tick used in leaky way SCC-SA1015
Performance
Critical

Using time.Tick in a way that will leak. Consider using time.NewTicker, and only use time.Tick in tests, commands and endless functions.

Storing non-pointer values in sync.Pool allocates memory SCC-SA6002
Performance
Major

A sync.Pool is used to avoid unnecessary allocations and reduce the amount of work the garbage collector has to do.

Range over the string directly SCC-SA6003
Performance
Major
Autofix

Loop directly over the runes in a string instead of converting the string to a slice of rune and then looping over the same.

Found inefficient string comparison with strings.ToLower or strings.ToUpper SCC-SA6005
Performance
Major
Autofix

Instead of using strings.ToLower/strings.ToUpper with equality check for string comparison, use strings.EqualFold directly.

Multiple append can be combined into a single call CRT-P0001
Performance
Major
Autofix

Multiple calls for append could be combined into a single call for append.

Function params involve heavy amount of copying CRT-P0003
Performance
Major

When a param big in size (more than 80 bytes) is passed to another function, it is better to pass a pointer to the value around, rather than the value itself.

strings.Index call cause unwanted allocations CRT-P0004
Performance
Major
Autofix

[]byte to string conversion is required when passing the arguments to strings.Index, leading to unwanted allocations. It is preferred to use calls that prevent (or minimize) such allocations (e.g., bytes.Index, etc.).

Copy of large value in range CRT-P0005
Performance
Major
Autofix

Use pointer to slice or array, to avoid copying the value that is ranged over.

Copy of large value inside loop CRT-P0006
Performance
Major

Avoid for loop range expressions that copy big objects for each iteration. It is recommended to use index-based access or use pointers instead.

Reorder operands for optimization GO-P3001
Performance
Critical
Autofix

Sometimes reordering the operands can save computational resources because of the properties of operators like "&&" (AND) or "||" (OR) in a binary expression.

For logical operators ("AND" and "OR"), if the evaluation of an expression exits before complete evaluation, it is known as "short-circuiting." A short circuit happens when the result is clear even before the complete evaluation of the expression, and the result is returned, avoiding unnecessary evaluation and leading to efficient processing.

Non-idiomatic slice zeroing for loop GO-P4001
Performance
Critical
Autofix

Using non-idiomatic slice zeroing might not get recognized by the compiler for further optimizations. Using the idiomatic slice zeroing method is recommended so the compiler can optimize it during compilation.

Prefer WriteByte over WriteRune for byte literals GO-P4005
Performance
Minor
Autofix

It is recommended to use WriteByte instead of WriteRune for writing byte literals. WriteRune appends the UTF-8 encoding of unicode code point to the buffer.

Use utf8.DecodeRuneInString instead of []rune(string)[0] GO-P4006
Performance
Major

It is recommended to use utf8.DecodeRuneInString instead of []rune(string)[0] to prevent unwanted rune slice allocation.

Use fmt.Fprint instead of (io.Writer).Write along with fmt.Sprint GO-P4007
Performance
Major
Autofix

It is recommended to use fmt.Fprint (and friends) instead of writing the result of an fmt.Sprint (and friends) call to write to an io.Writer. This reduces the number of allocations required, therefore improving performance.

Use (io.StringWriter).WriteString for writing strings GO-P4008
Performance
Major
Autofix

It is recommended to use (io.StringWriter).WriteString instead of (io.StringWriter).Write or io.WriteString for writing strings as it decreases the number of allocations required, therefore improving performance.