Skip to content

Commit

Permalink
Merge pull request #17 from go-faster/feat/speedup-ipv6
Browse files Browse the repository at this point in the history
feat(proto): improve IPv6 column speed
  • Loading branch information
ernado authored Jan 6, 2022
2 parents 69a2fcf + fd47dd1 commit f323d41
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 234 deletions.
298 changes: 149 additions & 149 deletions proto/_golden/col_arr_ipv6.hex

Large diffs are not rendered by default.

Binary file modified proto/_golden/col_arr_ipv6.raw
Binary file not shown.
98 changes: 49 additions & 49 deletions proto/_golden/col_ipv6.hex
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 |................|
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 |................|
00000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 |................|
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 |................|
00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05 |................|
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 |................|
00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07 |................|
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 |................|
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 |................|
000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a |................|
000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b |................|
000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c |................|
000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d |................|
000000e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0e |................|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f |................|
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 |................|
00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11 |................|
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 |................|
00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13 |................|
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 |................|
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 |................|
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16 |................|
00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 |................|
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18 |................|
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 |................|
000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a |................|
000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1b |................|
000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1c |................|
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1d |................|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1e |................|
000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1f |................|
00000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 |............... |
00000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 |...............!|
00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22 |..............."|
00000230 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 23 |...............#|
00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 24 |...............$|
00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 25 |...............%|
00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26 |...............&|
00000270 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 |...............'|
00000280 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 |...............(|
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 29 |...............)|
000002a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2a |...............*|
000002b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2b |...............+|
000002c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2c |...............,|
000002d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2d |...............-|
000002e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2e |................|
000002f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2f |.............../|
00000300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 |...............0|
00000310 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 31 |...............1|
00000010 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 |................|
00000040 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 |................|
00000050 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 |................|
00000060 00 00 00 00 00 00 00 06 00 00 00 00 00 00 00 00 |................|
00000070 00 00 00 00 00 00 00 07 00 00 00 00 00 00 00 00 |................|
00000080 00 00 00 00 00 00 00 08 00 00 00 00 00 00 00 00 |................|
00000090 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 |................|
000000a0 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00 |................|
000000b0 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 |................|
000000c0 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 00 00 |................|
000000d0 00 00 00 00 00 00 00 0d 00 00 00 00 00 00 00 00 |................|
000000e0 00 00 00 00 00 00 00 0e 00 00 00 00 00 00 00 00 |................|
000000f0 00 00 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 |................|
00000100 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 00 |................|
00000110 00 00 00 00 00 00 00 11 00 00 00 00 00 00 00 00 |................|
00000120 00 00 00 00 00 00 00 12 00 00 00 00 00 00 00 00 |................|
00000130 00 00 00 00 00 00 00 13 00 00 00 00 00 00 00 00 |................|
00000140 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 |................|
00000150 00 00 00 00 00 00 00 15 00 00 00 00 00 00 00 00 |................|
00000160 00 00 00 00 00 00 00 16 00 00 00 00 00 00 00 00 |................|
00000170 00 00 00 00 00 00 00 17 00 00 00 00 00 00 00 00 |................|
00000180 00 00 00 00 00 00 00 18 00 00 00 00 00 00 00 00 |................|
00000190 00 00 00 00 00 00 00 19 00 00 00 00 00 00 00 00 |................|
000001a0 00 00 00 00 00 00 00 1a 00 00 00 00 00 00 00 00 |................|
000001b0 00 00 00 00 00 00 00 1b 00 00 00 00 00 00 00 00 |................|
000001c0 00 00 00 00 00 00 00 1c 00 00 00 00 00 00 00 00 |................|
000001d0 00 00 00 00 00 00 00 1d 00 00 00 00 00 00 00 00 |................|
000001e0 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00 |................|
000001f0 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 00 00 |................|
00000200 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 00 |....... ........|
00000210 00 00 00 00 00 00 00 21 00 00 00 00 00 00 00 00 |.......!........|
00000220 00 00 00 00 00 00 00 22 00 00 00 00 00 00 00 00 |......."........|
00000230 00 00 00 00 00 00 00 23 00 00 00 00 00 00 00 00 |.......#........|
00000240 00 00 00 00 00 00 00 24 00 00 00 00 00 00 00 00 |.......$........|
00000250 00 00 00 00 00 00 00 25 00 00 00 00 00 00 00 00 |.......%........|
00000260 00 00 00 00 00 00 00 26 00 00 00 00 00 00 00 00 |.......&........|
00000270 00 00 00 00 00 00 00 27 00 00 00 00 00 00 00 00 |.......'........|
00000280 00 00 00 00 00 00 00 28 00 00 00 00 00 00 00 00 |.......(........|
00000290 00 00 00 00 00 00 00 29 00 00 00 00 00 00 00 00 |.......)........|
000002a0 00 00 00 00 00 00 00 2a 00 00 00 00 00 00 00 00 |.......*........|
000002b0 00 00 00 00 00 00 00 2b 00 00 00 00 00 00 00 00 |.......+........|
000002c0 00 00 00 00 00 00 00 2c 00 00 00 00 00 00 00 00 |.......,........|
000002d0 00 00 00 00 00 00 00 2d 00 00 00 00 00 00 00 00 |.......-........|
000002e0 00 00 00 00 00 00 00 2e 00 00 00 00 00 00 00 00 |................|
000002f0 00 00 00 00 00 00 00 2f 00 00 00 00 00 00 00 00 |......./........|
00000300 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 00 |.......0........|
00000310 00 00 00 00 00 00 00 31 00 00 00 00 00 00 00 00 |.......1........|
Binary file modified proto/_golden/col_ipv6.raw
Binary file not shown.
2 changes: 1 addition & 1 deletion proto/cmd/ch-gen-col/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func run() error {
}
}
for _, v := range variants {
if !v.Byte() && !v.IPv6() {
if !v.Byte() {
v.GenerateUnsafe = true
}
base := "col_" + v.ElemLower()
Expand Down
2 changes: 2 additions & 0 deletions proto/col_ipv6_safe_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions proto/col_ipv6_unsafe_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 6 additions & 34 deletions proto/ipv6.go
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
package proto

import (
"encoding/binary"

"inet.af/netaddr"
)

// IPv6 represents UInt128 address as UInt128 number.
//
// Not using netaddr.IP because UInt128 is more efficient.
//
// Use ToIP helper for convenience.
type IPv6 UInt128
// IPv6 represents IPv6 address.
type IPv6 [16]byte

// ToIP represents IPv6 as netaddr.IP.
func (v IPv6) ToIP() netaddr.IP {
var buf [16]byte
binary.BigEndian.PutUint64(buf[0:8], v.High)
binary.BigEndian.PutUint64(buf[8:16], v.Low)
return netaddr.IPv6Raw(buf)
return netaddr.IPv6Raw(v)
}

// ToIPv6 represents ip as IPv6.
func ToIPv6(ip netaddr.IP) IPv6 {
b := ip.As16()
return IPv6{
High: binary.BigEndian.Uint64(b[0:8]),
Low: binary.BigEndian.Uint64(b[8:16]),
}
}
func ToIPv6(ip netaddr.IP) IPv6 { return ip.As16() }

func binIPv6(b []byte) IPv6 {
_ = b[:16] // bounds check hint to compiler; see golang.org/issue/14808
// Using BigEndian for IPv6 as per ClickHouse implementation.
return IPv6{
High: binary.BigEndian.Uint64(b[0:8]),
Low: binary.BigEndian.Uint64(b[8:16]),
}
}

func binPutIPv6(b []byte, v IPv6) {
_ = b[:16] // bounds check hint to compiler; see golang.org/issue/14808
// Using BigEndian for IPv6 as per ClickHouse implementation.
binary.BigEndian.PutUint64(b[0:8], v.High)
binary.BigEndian.PutUint64(b[8:16], v.Low)
}
func binIPv6(b []byte) IPv6 { return *(*[16]byte)(b) }
func binPutIPv6(b []byte, v IPv6) { copy(b, v[:]) }
13 changes: 12 additions & 1 deletion proto/ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proto

import (
"bytes"
"encoding/binary"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -11,7 +12,17 @@ import (
)

func IPv6FromInt(v int) IPv6 {
return IPv6(UInt128FromInt(v))
s := IPv6{}
binary.BigEndian.PutUint64(s[:], uint64(v))
return s
}

func TestToIPv6(t *testing.T) {
v := netaddr.MustParseIP("2001:db8:ac10:fe01:feed:babe:cafe:0")
b := make([]byte, 16)
binPutIPv6(b, v.As16())
ip := binIPv6(b)
require.Equal(t, v, ip.ToIP())
}

func TestColIPv6_NetAddr(t *testing.T) {
Expand Down

0 comments on commit f323d41

Please sign in to comment.