Skip to content

Instantly share code, notes, and snippets.

Carlo Alberto Ferraris CAFxX

Block or report user

Report or block CAFxX

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
Last active Jun 6, 2019
Github wishlist

GitHub wishlist

Smart redirect for branch-less URLs

URLs of the form should redirect to if:

  • something does not match a branch name
  • something/somethingelse exists in defaultbranch

Smart redirect for renamed files

URLs of the form should redirect to if:

  • something/somethingelse else does not currently exist in branch
CAFxX / asm.s
Last active May 25, 2019
All the missing AMD64 atomic instructions for Golang
View asm.s
// Code generated by command: go run gen.go -out asm.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func AddInt8(addr *int8, a0 int8)
TEXT ·AddInt8(SB), NOSPLIT, $0-16
MOVQ addr+0(FP), AX
MOVB a0+8(FP), CL
Last active May 22, 2019
Index of gists
Last active Jun 5, 2019
Minimize allocations in Go

📂 Minimize allocations in Go

Working with protobuf in Go puts significant load on the memory subsystem, as protobuf-generated structures often contain a significant amount of pointers.

One way to minimize the number of allocations is to allocate all the fields at the same time, and then use internal pointers to wire them up.

Let's pretend you have (the generated Go code for) four messages A, B, C, and D (note: for clarity this is not really protobuf-generated code, but the technique

View asyncwriter.go
package main
import (
type AsyncWriter struct {
View .hyper.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
View build.txt
src/math/bits/bits.go:283:6: can inline Len as: func(uint) int { if UintSize == 32 { }; return Len64(uint64(x)) }
src/math/bits/bits.go:55:6: can inline TrailingZeros as: func(uint) int { if UintSize == 32 { }; return TrailingZeros64(uint64(x)) }
src/math/bits/bits.go:113:6: can inline OnesCount as: func(uint) int { if UintSize == 32 { }; return OnesCount64(uint64(x)) }
src/math/bits/bits.go:170:6: can inline RotateLeft as: func(uint, int) uint { if UintSize == 32 { }; return uint(RotateLeft64(uint64(x), k)) }
src/math/bits/bits.go:212:6: can inline Reverse as: func(uint) uint { if UintSize == 32 { }; return uint(Reverse64(uint64(x))) }
src/math/bits/bits.go:253:6: can inline ReverseBytes as: func(uint) uint { if UintSize == 32 { }; return uint(ReverseBytes64(uint64(x))) }
src/math/bits/bits.go:415:6: can inline Mul as: func(uint, uint) (uint, uint) { if UintSize == 32 { }; h, l = Mul64(uint64(x), uint64(y)); return uint(h), uint(l) }
src/math/bits/bits.go:458:6: can inline Div as: func(uint, uint, uin
CAFxX / partitioner.go
Last active Nov 15, 2018
Sarama BalancedAffinityPartitioner
View partitioner.go
package partitioner
A partitioner that assigns affinity from keys to partitions, while at the same time
attempting to spread the load across partitions. Affinity, to this end, is temporary.
This means that the affinity of a key to a partition changes over time.
There are three parameters that affect how often the affinity changes:
- every timeWindow affinity changes for all keys
- when, within a timeWindow, a key produces more than switchEveryBytes bytes or
switchEveryMessages messages the affinity of that key changes
View benchstat.out
name old time/op new time/op delta
BuildString_Builder/1Write_NoGrow-2 43.4ns ± 2% 43.4ns ± 1% ~ (p=0.392 n=13+13)
BuildString_Builder/3Write_NoGrow-2 163ns ± 1% 161ns ± 1% -0.77% (p=0.001 n=13+14)
BuildString_Builder/3Write_Grow-2 61.1ns ± 1% 61.7ns ± 2% +0.98% (p=0.001 n=15+15)
BuildString_ByteBuffer/1Write_NoGrow-2 75.4ns ± 2% 76.4ns ± 1% +1.24% (p=0.000 n=13+12)
BuildString_ByteBuffer/3Write_NoGrow-2 230ns ± 2% 335ns ±15% +45.70% (p=0.000 n=13+13)
BuildString_ByteBuffer/3Write_Grow-2 181ns ± 2% 247ns ±15% +36.28% (p=0.000 n=14+15)
GenericNoMatch-2 380ns ± 2% 407ns ± 6% +7.07% (p=0.000 n=15+15)
GenericMatch1-2 5.37µs ± 4% 5.28µs ± 4% -1.68% (p=0.023 n=15+15)
GenericMatch2-2 21.1µs ± 3% 20.8µs ± 2% ~ (p=0.098 n=15+15)
CAFxX / intern.go
Last active Sep 26, 2018 — forked from karlseguin/intern.go
String interning in Golang
View intern.go
package intern
import (
type Pool struct {
lookup map[string]string
You can’t perform that action at this time.