A better Generic Pool (sync.Pool)

Overview

  the project to show your appreciation. ↗️

go-pool

A Better 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 by reducing the number of 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
  • Returns the number of items in the pool (idle and in-use)

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

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

Example

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

pool := pool.New(5) // maximum of 5 items in pool
pool.SetFactory(func() interface{} {
	return &X{}
})

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

// Use item here or mark as invalid
x := item.Item.(*X) // Use item here
item.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)
You might also like...
Helper library for full uint64 randomness, pool backed for efficient concurrency

fastrand64-go Helper library for full uint64 randomness, pool backed for efficient concurrency Inspired by https://github.com/valyala/fastrand which i

generic sync.Pool

syncpool The mkm.pub/syncpool package provides a generic wrapper around the sync.Pool structure. This package is just a thin wrapper around the underl

Better sync package for Go.

synx Better sync package for Go. Rationale TODO. Note For better sync/atomic package see atomix. Features Simple API. Easy to integrate. Optimized for

grafana-sync Keep your grafana dashboards in sync.

grafana-sync Keep your grafana dashboards in sync. Table of Contents grafana-sync Table of Contents Installing Getting Started Pull Save all dashboard

Provider-generic-workflows - A generic provider which uses argo workflows to define the backend actions.

provider-generic-workflows provider-generic-workflows is a generic provider which uses argo workflows for managing the external resource. This will re

Go-generic-unboxing - A quick ready to ship demo for go generic using the official example

Go generic This repo contain basic demo for installing and running go1.18beta1 v

Generic - Golang generic example

泛型 场景 假设需要写一个列表总数计算的函数,根据不同数据类型,我们可能分别要写 SumInts(data []int),SumFloats(data []fl

This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event.

observer This library implements the pub/sub pattern in a generic way. It uses Go's generic types to declare the type of the event. Usage go get githu

TechTalk: Procesamiento masivo de datos con Go y sync.Pool

Procesamiento masivo de datos en Go Si quieres probarlo, descarga alguno de los

gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.

gpool - a generic context-aware resizable goroutines pool to bound concurrency. Installation $ go get github.com/sherifabdlnaby/gpool import "github.c

a generic object pool for golang

Go Commons Pool The Go Commons Pool is a generic object pool for Golang, direct rewrite from Apache Commons Pool. Features Support custom PooledObject

golang worker pool , Concurrency limiting goroutine pool

golang worker pool 中文说明 Concurrency limiting goroutine pool. Limits the concurrency of task execution, not the number of tasks queued. Never blocks su

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.
Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

Gowl is a process management and process monitoring tool at once. An infinite worker pool gives you the ability to control the pool and processes and monitor their status.

A mining pool proxy tool, support BTC, ETH, ETC, XMR mining pool, etc.

Tier2Pool A mining pool proxy tool, support BTC, ETH, ETC, XMR mining pool, etc. Build I use Ubuntu as a demo. sudo update sudo apt install git make s

Poweth - Etchash go module intended for use by core-pool (and open-ethereum-pool)

go-etchash Etchash go module intended for use by core-pool (and open-ethereum-po

Golang Implementation of Worker Pool/ Thread Pool

Golang Implementation of Worker Pool/ Thread Pool

Go-miningcore-pool - Miningcore Pool written in GOlang

Go-Miningcore-Pool (COMING SOON) Miningcore Pool written in GOlang 0x01 Configur

Go-ldap-pool - A simple connection pool for go-ldap

Basic connection pool for go-ldap This little library use the go-ldap library an

Work pool channlege - An url hash retriever worker pool for getting hash digest for a collection of urls

Code challenge The aim of this project is to provide an url hash retriever worke

Owner
null
Maintain a lower-bitrate copy of a music library in sync with the main copy.

msync Maintain a lower-bitrate copy of your music library, in sync with the main copy.

Chris Dzombak 18 Mar 6, 2022
Package ethtool allows control of the Linux ethtool generic netlink interface.

ethtool Package ethtool allows control of the Linux ethtool generic netlink interface.

Matt Layher 47 Sep 7, 2022
Go library for decoding generic map values into native Go structures and vice versa.

mapstructure mapstructure is a Go library for decoding generic map values to structures and vice versa, while providing helpful error handling. This l

Mitchell Hashimoto 6.2k Sep 27, 2022
conditiond is a generic constraint and policy evaluator.

conditiond conditiond is a generic constraint and policy evaluator. This tool lets you define constraints in data and evaluate them at run time. It's

Tadas Vilkeliskis 22 Mar 23, 2022
Some utility functions for generic types in Go.

GOUF - Utility Functions for generic types Go team released Go 1.18 beta recently with support for Generics(a.k.a type parameters). This package provi

Akshay Bharambe 18 Apr 13, 2022
Generic Free List implementation to reuse memory and avoid allocations

gofl GOFL provides a Generic Free List implementation for Go. Installation This

Akshay Bharambe 1 Dec 26, 2021
Slice - provides generic Map, Reduce and Filter functions for Go.

slice slice is a simple Go package to provide generic versions of Map, Reduce and Filter on slices. I mainly wrote it as an exercise to get more famil

Andreas Krennmair 23 Sep 19, 2022
Di - A (very) WIP Go 1.18+ generic dependency injection package based on type reflection

di A (very) WIP Go 1.18+ generic dependency injection package based on type refl

Ringo Hoffmann 5 Apr 26, 2022
🚀 GoDI: Generic based DI in Go

?? GoDI: Generic based DI in Go Installation DI: go get -u github.com/MaximZayats/godi/ import "github.com/MaximZayats/godi/di" CMD: go get -u github.

Maxim 8 Aug 14, 2022
Generic-based collection tools

go-collection go collection is a tool implemented using generic, it can help you process slice/map data quickly and easily convert between them. Note:

王杨 10 Jun 21, 2022