From 327b8f52395403da258e8a3738ff550a7a4b9d9e Mon Sep 17 00:00:00 2001 From: CodingTil <36734749+CodingTil@users.noreply.github.com> Date: Fri, 2 May 2025 19:28:56 +0200 Subject: [PATCH] replace encoding/json with faster go-json --- cmd/headscale/cli/mockoidc.go | 2 +- cmd/headscale/cli/utils.go | 2 +- go.mod | 1 + go.sum | 2 ++ hscontrol/capver/gen/main.go | 2 +- hscontrol/db/db.go | 2 +- hscontrol/db/node.go | 2 +- hscontrol/debug.go | 2 +- hscontrol/derp/derp.go | 2 +- hscontrol/derp/server/derp_server.go | 2 +- hscontrol/dns/extrarecords.go | 2 +- hscontrol/handlers.go | 2 +- hscontrol/mapper/mapper.go | 2 +- hscontrol/mapper/tail_test.go | 2 +- hscontrol/noise.go | 2 +- hscontrol/policy/v1/acls.go | 2 +- hscontrol/policy/v1/acls_types.go | 2 +- hscontrol/policy/v2/policy.go | 2 +- hscontrol/policy/v2/types.go | 2 +- hscontrol/policy/v2/types_test.go | 2 +- hscontrol/types/users.go | 2 +- hscontrol/types/users_test.go | 2 +- integration/cli_test.go | 2 +- integration/derp_verify_endpoint_test.go | 2 +- integration/dns_test.go | 2 +- integration/general_test.go | 2 +- integration/hsic/hsic.go | 2 +- integration/scenario.go | 2 +- integration/tsic/tsic.go | 2 +- 29 files changed, 30 insertions(+), 27 deletions(-) diff --git a/cmd/headscale/cli/mockoidc.go b/cmd/headscale/cli/mockoidc.go index 309ad67d..1f21c06f 100644 --- a/cmd/headscale/cli/mockoidc.go +++ b/cmd/headscale/cli/mockoidc.go @@ -1,7 +1,7 @@ package cli import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "net" "net/http" diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index ff1137be..231b9365 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -3,7 +3,7 @@ package cli import ( "context" "crypto/tls" - "encoding/json" + "github.com/goccy/go-json" "fmt" "os" diff --git a/go.mod b/go.mod index ed1f31c4..19348a11 100644 --- a/go.mod +++ b/go.mod @@ -127,6 +127,7 @@ require ( github.com/go-json-experiment/json v0.0.0-20250103232110-6a9a0fde9288 // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/go-viper/mapstructure/v2 v2.2.1 // indirect + github.com/goccy/go-json v0.10.5 // indirect github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect diff --git a/go.sum b/go.sum index 88263ed4..2a55e13a 100644 --- a/go.sum +++ b/go.sum @@ -193,6 +193,8 @@ github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlnd github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM= github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY= +github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= +github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466 h1:sQspH8M4niEijh3PFscJRLDnkL547IeP7kpPe3uUhEg= github.com/godbus/dbus/v5 v5.1.1-0.20230522191255-76236955d466/go.mod h1:ZiQxhyQ+bbbfxUKVvjfO498oPYvtYhZzycal3G/NHmU= diff --git a/hscontrol/capver/gen/main.go b/hscontrol/capver/gen/main.go index 3b31686d..6d887cca 100644 --- a/hscontrol/capver/gen/main.go +++ b/hscontrol/capver/gen/main.go @@ -3,7 +3,7 @@ package main //go:generate go run main.go import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "io" "log" diff --git a/hscontrol/db/db.go b/hscontrol/db/db.go index d299771f..bb305ba5 100644 --- a/hscontrol/db/db.go +++ b/hscontrol/db/db.go @@ -3,7 +3,7 @@ package db import ( "context" "database/sql" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "net/netip" diff --git a/hscontrol/db/node.go b/hscontrol/db/node.go index ed9e1f73..a5573978 100644 --- a/hscontrol/db/node.go +++ b/hscontrol/db/node.go @@ -1,7 +1,7 @@ package db import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "net/netip" diff --git a/hscontrol/debug.go b/hscontrol/debug.go index ef28a955..b5731044 100644 --- a/hscontrol/debug.go +++ b/hscontrol/debug.go @@ -1,7 +1,7 @@ package hscontrol import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/http" diff --git a/hscontrol/derp/derp.go b/hscontrol/derp/derp.go index 9d358598..3dbf39c0 100644 --- a/hscontrol/derp/derp.go +++ b/hscontrol/derp/derp.go @@ -2,7 +2,7 @@ package derp import ( "context" - "encoding/json" + "github.com/goccy/go-json" "io" "net/http" "net/url" diff --git a/hscontrol/derp/server/derp_server.go b/hscontrol/derp/server/derp_server.go index 0c97806f..4b4558f3 100644 --- a/hscontrol/derp/server/derp_server.go +++ b/hscontrol/derp/server/derp_server.go @@ -3,7 +3,7 @@ package server import ( "bufio" "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" "net" "net/http" diff --git a/hscontrol/dns/extrarecords.go b/hscontrol/dns/extrarecords.go index e667c562..58faed62 100644 --- a/hscontrol/dns/extrarecords.go +++ b/hscontrol/dns/extrarecords.go @@ -2,7 +2,7 @@ package dns import ( "crypto/sha256" - "encoding/json" + "github.com/goccy/go-json" "fmt" "os" "sync" diff --git a/hscontrol/handlers.go b/hscontrol/handlers.go index e55fce49..5e17b8b1 100644 --- a/hscontrol/handlers.go +++ b/hscontrol/handlers.go @@ -1,7 +1,7 @@ package hscontrol import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/hscontrol/mapper/mapper.go b/hscontrol/mapper/mapper.go index 662e491c..fa57fd77 100644 --- a/hscontrol/mapper/mapper.go +++ b/hscontrol/mapper/mapper.go @@ -2,7 +2,7 @@ package mapper import ( "encoding/binary" - "encoding/json" + "github.com/goccy/go-json" "fmt" "io/fs" "net/url" diff --git a/hscontrol/mapper/tail_test.go b/hscontrol/mapper/tail_test.go index 1c3c018f..b24c5882 100644 --- a/hscontrol/mapper/tail_test.go +++ b/hscontrol/mapper/tail_test.go @@ -1,7 +1,7 @@ package mapper import ( - "encoding/json" + "github.com/goccy/go-json" "net/netip" "testing" "time" diff --git a/hscontrol/noise.go b/hscontrol/noise.go index 1269d032..f306d1f3 100644 --- a/hscontrol/noise.go +++ b/hscontrol/noise.go @@ -2,7 +2,7 @@ package hscontrol import ( "encoding/binary" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/hscontrol/policy/v1/acls.go b/hscontrol/policy/v1/acls.go index 9ab1b244..344ae552 100644 --- a/hscontrol/policy/v1/acls.go +++ b/hscontrol/policy/v1/acls.go @@ -1,7 +1,7 @@ package v1 import ( - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/hscontrol/policy/v1/acls_types.go b/hscontrol/policy/v1/acls_types.go index 8c4584c7..3fa08b24 100644 --- a/hscontrol/policy/v1/acls_types.go +++ b/hscontrol/policy/v1/acls_types.go @@ -1,7 +1,7 @@ package v1 import ( - "encoding/json" + "github.com/goccy/go-json" "net/netip" "strings" diff --git a/hscontrol/policy/v2/policy.go b/hscontrol/policy/v2/policy.go index ec4b7737..1570fa5e 100644 --- a/hscontrol/policy/v2/policy.go +++ b/hscontrol/policy/v2/policy.go @@ -1,7 +1,7 @@ package v2 import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/netip" "strings" diff --git a/hscontrol/policy/v2/types.go b/hscontrol/policy/v2/types.go index 2ee998b6..88f6e9eb 100644 --- a/hscontrol/policy/v2/types.go +++ b/hscontrol/policy/v2/types.go @@ -2,7 +2,7 @@ package v2 import ( "bytes" - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/netip" "strings" diff --git a/hscontrol/policy/v2/types_test.go b/hscontrol/policy/v2/types_test.go index b428c55a..e696d233 100644 --- a/hscontrol/policy/v2/types_test.go +++ b/hscontrol/policy/v2/types_test.go @@ -1,7 +1,7 @@ package v2 import ( - "encoding/json" + "github.com/goccy/go-json" "net/netip" "strings" "testing" diff --git a/hscontrol/types/users.go b/hscontrol/types/users.go index 471cb1e5..0adc18df 100644 --- a/hscontrol/types/users.go +++ b/hscontrol/types/users.go @@ -3,7 +3,7 @@ package types import ( "cmp" "database/sql" - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/mail" "net/url" diff --git a/hscontrol/types/users_test.go b/hscontrol/types/users_test.go index 12029701..628454a7 100644 --- a/hscontrol/types/users_test.go +++ b/hscontrol/types/users_test.go @@ -2,7 +2,7 @@ package types import ( "database/sql" - "encoding/json" + "github.com/goccy/go-json" "testing" "github.com/google/go-cmp/cmp" diff --git a/integration/cli_test.go b/integration/cli_test.go index 435b7e55..b2a79356 100644 --- a/integration/cli_test.go +++ b/integration/cli_test.go @@ -2,7 +2,7 @@ package integration import ( "cmp" - "encoding/json" + "github.com/goccy/go-json" "fmt" "strconv" "strings" diff --git a/integration/derp_verify_endpoint_test.go b/integration/derp_verify_endpoint_test.go index 20ed4872..4243d9e0 100644 --- a/integration/derp_verify_endpoint_test.go +++ b/integration/derp_verify_endpoint_test.go @@ -1,7 +1,7 @@ package integration import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "net" "strconv" diff --git a/integration/dns_test.go b/integration/dns_test.go index ef6c479b..a3a1b2c2 100644 --- a/integration/dns_test.go +++ b/integration/dns_test.go @@ -1,7 +1,7 @@ package integration import ( - "encoding/json" + "github.com/goccy/go-json" "fmt" "strings" "testing" diff --git a/integration/general_test.go b/integration/general_test.go index 292eb5ca..3ce3b9f5 100644 --- a/integration/general_test.go +++ b/integration/general_test.go @@ -2,7 +2,7 @@ package integration import ( "context" - "encoding/json" + "github.com/goccy/go-json" "fmt" "net/netip" "strconv" diff --git a/integration/hsic/hsic.go b/integration/hsic/hsic.go index 27e18697..bc47213c 100644 --- a/integration/hsic/hsic.go +++ b/integration/hsic/hsic.go @@ -3,7 +3,7 @@ package hsic import ( "cmp" "crypto/tls" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/integration/scenario.go b/integration/scenario.go index 7d4d62d1..4c7c4a64 100644 --- a/integration/scenario.go +++ b/integration/scenario.go @@ -3,7 +3,7 @@ package integration import ( "context" "crypto/tls" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io" diff --git a/integration/tsic/tsic.go b/integration/tsic/tsic.go index 57770d41..2e3f7982 100644 --- a/integration/tsic/tsic.go +++ b/integration/tsic/tsic.go @@ -4,7 +4,7 @@ import ( "archive/tar" "bytes" "context" - "encoding/json" + "github.com/goccy/go-json" "errors" "fmt" "io"