Get your context value faster

Go Report Card PkgGoDev Github Workflow Build Status codecov pre-commit

goctx

Get your context value faster

How to use

Replace

v := ctx.Value(key)

With

v := goctx.Value(ctx, key)

Benchmark

There will be little difference when there is only 1~2 context.WithXXX calls

With 5 context.WithXXX calls

BenchmarkValue/5/non_parallel/std-8 35313684 34.2 ns/op
BenchmarkValue/5/non_parallel/goctx-8 42801348 30.0 ns/op
BenchmarkValue/5/non_parallel/pure_map-8 16655377 72.8 ns/op
BenchmarkValue/5/parallel/std-8 168420460 7.09 ns/op
BenchmarkValue/5/parallel/goctx-8 185695462 6.35 ns/op
BenchmarkValue/5/parallel/pure_map-8 67944997 17.6 ns/op

With 20 context.WithXXX calls

BenchmarkValue/20/non_parallel/std-8 7137338 168 ns/op
BenchmarkValue/20/non_parallel/goctx-8 14623730 81.4 ns/op
BenchmarkValue/20/non_parallel/pure_map-8 5282458 235 ns/op
BenchmarkValue/20/parallel/std-8 42826857 27.9 ns/op
BenchmarkValue/20/parallel/goctx-8 79149823 15.1 ns/op
BenchmarkValue/20/parallel/pure_map-8 22206717 53.8 ns/op

As we can see from the benchmark test, the map implementation is slower than the standard one, so it is not recommended to use RegisterValueFunc to register a context value function, unless you do not want to see nested stack with Value method call (That's also the reason why RegisterValueFunc is kept even it is not fast)

Owner
Interested in Golang, C++, Kubernetes, Docker, CNCF. PS: Currently not playing vanilla WoW so the addons will probably NOT be updated
null
Similar Resources

containedctx detects is a linter that detects struct contained context.Context field

containedctx containedctx detects is a linter that detects struct contained context.Context field Instruction go install github.com/sivchari/contained

Oct 22, 2022

Example code to demonstrate how to mock external clients via context.Context

Mocking external client libraries using context.Context This code is paired with a blog post: Mocking external client libraries using context.Context

Nov 6, 2022

The web framework for writing faster sites, faster

Gondola The web framework for writing faster sites, faster. Written in Go. View documentation at http://gondolaweb.com. Unless indicated otherwise at

Nov 20, 2022

A faster RWLock primitive in Go, 2-3 times faster than RWMutex. A Go implementation of concurrency control algorithm in paper Left-Right - A Concurrency Control Technique with Wait-Free Population Oblivious Reads

Go Left Right Concurrency A Go implementation of the left-right concurrency control algorithm in paper Left-Right - A Concurrency Control Technique w

Jan 6, 2023

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Gin Web Framework Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks

Jan 2, 2023

A faster method to get elements from an interface (Struct or Slice type) for Go.

A faster method to get elements from an interface (Struct or Slice type) for Go.

May 13, 2022

Monitor your Website and APIs from your Computer. Get Notified through Slack, E-mail when your server is down or response time is more than expected.

Monitor your Website and APIs from your Computer. Get Notified through Slack, E-mail when your server is down or response time is more than expected.

StatusOK Monitor your Website and APIs from your computer.Get notified through Slack or E-mail when your server is down or response time is more than

Dec 27, 2022

kcon is a simple CLI tool to switch the context of your Kubeconfig file.

kcon kcon is a simple CLI tool to switch the context of your Kubeconfig file. Scope The code published here is educational only. Usage Usage of kcon:

Oct 14, 2021

A restart tracker that gives context to what is restarting in your cluster

A restart tracker that gives context to what is restarting in your cluster

Dec 20, 2022

Kubeswitch - Easier way to switch your kubernetes context

Switch Kubectl Context Easier way to switch your kubernetes context Set PATH Dow

Jun 17, 2022

OCI transport plugin for apt-get (i.e., apt-get over ghcr.io)

apt-transport-oci: OCI transport plugin for apt-get (i.e., apt-get over ghcr.io) apt-transport-oci is an apt-get plugin to support distributing *.deb

Nov 1, 2022

A library for the MIGP (Might I Get Pwned) protocolA library for the MIGP (Might I Get Pwned) protocol

MIGP library This contains a library for the MIGP (Might I Get Pwned) protocol. MIGP can be used to build privacy-preserving compromised credential ch

Dec 3, 2022

It is a clone of the CRUD operations on Instagram which can create, get, create posts and get the post along with pagination

It is a clone of the CRUD operations on Instagram which can create, get, create posts and get the post along with pagination

Instagram-API-Clone It is a basic version of a RESTful API based on Instagram where we can create user, get the users, create post and get post and ge

Jan 25, 2022

this allows you to get the real link of without get tracked bit.ly

this allows you to get the real link of without get tracked bit.ly

check the real url from a url shortener (bit.ly) Also you can use it as an API example with deno const rawResponse = await fetch("https://anti-url-s

Feb 19, 2022

Redis-benchmark - Simple get, mget and pipelined get benchmark.

redis-benchmark Simple get, mget and pipelined get benchmark. Usage git clone https://github.com/Ali-A-A/redis-benchmark.git cd ./redis-benchmark dock

Dec 31, 2021

Get-latest - Get the latest repository version

Get-latest - Get the latest repository version

get-latest Get the latest repository version Usage routes for public repos - /:

Nov 30, 2022

htf (Host That File) is a tool to make serving up your favorite pentest tools simpler and faster.

htf (Host That File) is a tool to make serving up your favorite pentest tools simpler and faster.

htf htf (Host That File) is a tool to make serving up your favorite pentest tools simpler and faster. All you need to do is populate the htf configura

Nov 28, 2021

Get the value in JSON by path, no need for struct

Get the value in JSON by path, no need for struct

Dec 6, 2021

:steam_locomotive: Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.

Package form Package form Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. It has the following features: Supports map of

Dec 26, 2022
Golang's Context package examples

Golang's Context package examples To run the server: go run . api-up The server will be started in port 3001 In the file "router.go" of the folder "ap

Dec 22, 2021
Go-context - A simply tryout of how contexts work in golang

go-context A simply tryout of how contexts work in golang The example here execu

Apr 7, 2022
TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON

TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON.

Dec 10, 2022
Simple REST API to get time from many different timezones

Timezone API Simple REST API for getting current time in different timezones. This is the first assignment from Rest-Based Microservices API Developme

Oct 31, 2021
Go-userapi-rest - Build a RESTful API that can get/create/update/delete user data from a persistence database

GO ASSIGNMENT Overview of the Task Context Build a RESTful API that can get/crea

Sep 6, 2022
A simple blog framework built with GO. Uses HTML files and a JSON dict to give you more control over your content.

Go-Blog A simple template based blog framework. Instructions Built for GO version: 1 See the Documentation or Getting Started pages in the wiki. Notes

Sep 10, 2022
Include files in your binary the easy way

New Projects should use the official embed package instead, which was added in go 1.16. binclude binclude is a tool for including static files into Go

Dec 18, 2022
Impersonate Your GitHub App In A GitHub Action

Impersonate Your GitHub App In A GitHub Action This action helps you retrieve an authenticated app token with a GitHub app id and a app private key. Y

Nov 29, 2021
Start and finish your Go apps gracefully, even in the case of panics

Relax Relax - verb antonym for panic. In the context of Go programs, relax means to make critical failures less severe so that graceful shutdown is ne

May 7, 2023
Morecontext - Context.Context helpers to make your life slightly easier

morecontext context.Context helpers to make your life slightly easier. -- import

Mar 5, 2022