• Stars
    star
    3
  • Rank 3,845,519 (Top 78 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Generic Free List implementation to reuse memory and avoid allocations

gofl

GOFL provides a Generic Free List implementation for Go.

Installation

This package requires go1.18 or later.

go get github.com/akshaybharambe14/gofl

Why?

Free list pattern provides a way to reuse already initialized memory. GOFL helps you to grab an item from the free list and put it back to the free list once it is no longer needed. This helps in allocating limited amount of memory, resulting in better performance.

You can have a look at leaky buffer example from effective go documentation. This package is inspired by the same implementation.

A general usage would be:

newFn := func() T {...}
max := uint(10)
fl := gofl.NewFreeList(max, newFn)
...
t := fl.Get() // get t from free list
process(..., t) // reuse memory
fl.Put(t) // put t back to free list; will be reused eventually

Following benchmarks depict the use of free list in finding duplicates in a slice.

$ github.com/akshaybharambe14/gofl/example> go1.18beta1 test -bench . -benchmem
goos: windows
goarch: amd64
pkg: github.com/akshaybharambe14/gofl/example
cpu: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
BenchmarkFindDuplicate-4                 1693132               681.7 ns/op           162 B/op          1 allocs/op
BenchmarkFindDuplicateWithFreeList-4     2151346               554.3 ns/op             2 B/op          0 allocs/op
PASS
ok      github.com/akshaybharambe14/gofl/example        3.855s

As you can see, it avoids creation and allocations of temporary map, resulting in better performance.

For more details see example.

Contact

Akshay Bharambe


If this is not something you are looking for, you can check other similar packages on pkg.go.dev, go.libhunt.com.

Do let me know if you have any feedback. Leave a ⭐ this helps you!

More Repositories

1

gouf

Most commonly used utility/helper functions for generic types in Go.
Go
18
star
2

golang-examples

This repository contains sample golang examples which I come across while learning or trying new things. It also contains tests and benchmarks of various operations.
Go
11
star
3

docgo

Now you are just a click away from official package documentation for Go repositories. DOCGO is a handy browser extension 🧱 to redirect from Go source code repositories to their official documentation 📄.
CSS
11
star
4

go-jsonc

go-jsonc provides a way to work with commented json by converting it to plain json.
Go
10
star
5

ijson

Go package to quickly query and manipulate interface data.
Go
10
star
6

gowp

High performance, type safe, concurrency limiting worker pool package for golang!
Go
4
star
7

cloud-native-go

Introduction to docker and kubernetes with cloud native Go.
2
star
8

vue-js-template-project

A template project for vue js with configured eslint and prettier.
Vue
2
star
9

go-docker

Simple tutorial to containerize and publish your go app to Docker
Dockerfile
2
star
10

go-workerpool

A worker pool in go.
Go
2
star
11

golang-concurrent-csv

golang-concurrent-csv
1
star
12

spinner

Simple spinner for golang CLI apps.
Go
1
star
13

akshaybharambe14.github.io

Portfolio website
1
star
14

modulesExample

An example to get started with golang modules
Go
1
star
15

portfolioDev

Portfoio Website
1
star
16

akshaybharambe14

1
star
17

go-unusual

Some functionalities that are unusual/unsafe, but are useful in some edge/exceptional cases.
1
star
18

golang-postgresql-example

Go
1
star
19

gohooks

GoHooks make it easy to send and consume secured web-hooks from a Go application
Go
1
star
20

one-click-hugo-cms

CSS
1
star
21

go-generics-tests-bug

Details of a bug in compiling tests files with generic code.
Go
1
star
22

go-rotate

Go
1
star