New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/pixeldrama/go-heap-performance

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/pixeldrama/go-heap-performance

  • v0.0.0-20240521145936-fd471a8bf10e
  • Source
  • Go
  • Socket score

Version published
Created
Source

Heap vs Stack Performance

Call By Value and Call by Reference

  • Call by value default for datatypes: int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, float32, float64, string, bool, byte, rune, Array, Structs
  • Slices and Maps are Called by Reference by default
  • Receiver functions

Stack vs Heap

  • Call by value does not use the heap, no GC involved here
  • Call by reference could use the heap, it is not always the case

Execution

go build -gcflags '-m -l' # -m print decisions from compile, -l avoid inlining
go test -bench=. -benchmem 

Some Take Away

  • Call by seems to be faster in our artificial example
  • API-Design mutability should not be mixed
  • No absense value is possible (like nil), typical solution is to wrap it into a struct:
type Counter struct {
    valid boolean
    i int
}

References

  • Benchmarking Generics in Go
  • Golang Pass by value vs Pass by reference
  • Understanding Allocations in Go
  • When to use Pointers

FAQs

Package last updated on 21 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc