Skip to content

rocketlaunchr/go-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⭐   the project to show your appreciation. ↗️

go-pool

A Generic sync.Pool

This package is a thin wrapper over the Pool provided by the sync package. The Pool is an essential package to obtain maximum performance. It does so by reducing memory allocations.

Extra Features

  • Invalidate an item from the Pool (so it never gets used again)
  • Set a maximum number of items for the Pool (Limit pool growth)
  • Return the number of items in the pool (idle and in-use)
  • Designed for concurrency
  • Fully Generic

When should I use a pool?

If you frequently allocate many objects of the same type and you want to save some memory allocation and garbage allocation overhead — @jrv

Read How did I improve latency by 700% using sync.Pool

Example

import "github.com/rocketlaunchr/go-pool"

type X struct {}

pool := pool.New(func() *X {
  return &X{}
}, 5) // maximum of 5 items can be borrowed at a time

borrowed := pool.Borrow()
defer borrowed.Return()

// Use item here or mark as invalid
x := borrowed.Item() // Use Item of type: *X
borrowed.MarkAsInvalid()

Other useful packages

  • awesome-svelte - Resources for killing react
  • dataframe-go - Statistics and data manipulation
  • dbq - Zero boilerplate database operations for Go
  • electron-alert - SweetAlert2 for Electron Applications
  • google-search - Scrape google search results
  • igo - A Go transpiler with cool new syntax such as fordefer (defer for for-loops)
  • mysql-go - Properly cancel slow MySQL queries
  • react - Build front end applications using Go
  • remember-go - Cache slow database queries
  • testing-go - Testing framework for unit testing

Logo Credits

  1. Renee French (gopher)
  2. Samuel Jirénius (illustration)