Skip to content

Commit

Permalink
Replace standard json library by segmentio's library
Browse files Browse the repository at this point in the history
The segment json library is a drop-in replacement that it's faster
than the standard library. In this case it's ~37% faster.

goos: darwin
goarch: arm64
pkg: github.com/aws/aws-lambda-go/lambda
       │ bench.orig.txt │           bench.json.txt            │
       │     sec/op     │   sec/op     vs base                │
JSON-8      7.901µ ± 0%   4.985µ ± 0%  -36.90% (p=0.000 n=40)

       │ bench.orig.txt │             bench.json.txt             │
       │      B/op      │     B/op       vs base                 │
JSON-8     4.353Ki ± 0%   38.273Ki ± 0%  +779.34% (p=0.000 n=40)

       │ bench.orig.txt │       bench.json.txt       │
       │   allocs/op    │ allocs/op   vs base        │
JSON-8       31.00 ± 0%   17.00 ± 0%  -45.16% (n=40)

re aws#381
  • Loading branch information
dcu committed Oct 28, 2023
1 parent c4e28da commit 5ff5739
Show file tree
Hide file tree
Showing 72 changed files with 98 additions and 78 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Expand Up @@ -10,6 +10,7 @@ jobs:
strategy:
matrix:
go:
- "1.21"
- "1.20"
- "1.19"
- "1.18"
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Expand Up @@ -18,6 +18,6 @@ run:

linters-settings:
stylecheck:
go: "1.20"
go: "1.21"
checks: ["all"]
initialisms: ["AWS", "ARN", "IAM", "MQTT", "ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS", "VPC"]
2 changes: 1 addition & 1 deletion cfn/event_test.go
Expand Up @@ -3,7 +3,7 @@
package cfn

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion cfn/response.go
Expand Up @@ -4,8 +4,8 @@ package cfn

import (
"bytes"
"encoding/json"
"fmt"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"log"
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion cfn/wrap.go
Expand Up @@ -4,8 +4,8 @@ package cfn

import (
"context"
"encoding/json"
"errors"
"github.com/segmentio/encoding/json"
"log"
"net/http"

Expand Down
2 changes: 1 addition & 1 deletion cfn/wrap_test.go
Expand Up @@ -5,8 +5,8 @@ package cfn
import (
"bytes"
"context"
"encoding/json"
"errors"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"net/http"
"testing"
Expand Down
2 changes: 1 addition & 1 deletion events/README_Chime_Bots.md
Expand Up @@ -11,7 +11,7 @@ import (
"context"
"net/http"
"bytes"
"encoding/json"
"github.com/segmentio/encoding/json"
"errors"
"strconv"

Expand Down
2 changes: 1 addition & 1 deletion events/README_ClientVPN.md
Expand Up @@ -8,7 +8,7 @@ import (
"log"
"net"

"encoding/json"
"github.com/segmentio/encoding/json"

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
Expand Down
2 changes: 1 addition & 1 deletion events/README_KinesisDataAnalytics.md
Expand Up @@ -10,7 +10,7 @@ package main

import (
"context"
"encoding/json"
"github.com/segmentio/encoding/json"
"fmt"
"log"

Expand Down
2 changes: 1 addition & 1 deletion events/activemq_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/alb_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/apigw_test.go
Expand Up @@ -3,7 +3,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/appsync.go
@@ -1,6 +1,6 @@
package events

import "encoding/json"
import "github.com/segmentio/encoding/json"

// Deprecated: AppSyncResolverTemplate does not represent resolver events sent by AppSync. Instead directly model your input schema, or use map[string]string, json.RawMessage, interface{}, etc..
type AppSyncResolverTemplate struct {
Expand Down
2 changes: 1 addition & 1 deletion events/appsync_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/attributevalue.go
Expand Up @@ -5,9 +5,9 @@ package events
import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"github.com/segmentio/encoding/json"
"strconv"
)

Expand Down
2 changes: 1 addition & 1 deletion events/attributevalue_test.go
Expand Up @@ -4,7 +4,7 @@ package events

import (
"encoding/base64"
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion events/autoscaling_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/chime_bot_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"
"time"

Expand Down
2 changes: 1 addition & 1 deletion events/clientvpn_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/cloudwatch_events.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion events/cloudwatch_events_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/cloudwatch_logs.go
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"compress/gzip"
"encoding/base64"
"encoding/json"
"github.com/segmentio/encoding/json"
)

// CloudwatchLogsEvent represents raw data from a cloudwatch logs event
Expand Down
2 changes: 1 addition & 1 deletion events/cloudwatch_logs_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"reflect"
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/codebuild.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion events/codebuild_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"
"time"
Expand Down
2 changes: 1 addition & 1 deletion events/codedeploy_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil" //nolint: staticcheck
"testing"
Expand Down
2 changes: 1 addition & 1 deletion events/codepipeline_cloudwatch_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil" //nolint: staticcheck
"testing"
Expand Down
2 changes: 1 addition & 1 deletion events/codepipeline_job_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/codepipeline_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/cognito_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/config_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/connect_test.go
Expand Up @@ -3,7 +3,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/duration.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"math"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion events/dynamodb_test.go
Expand Up @@ -3,7 +3,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/ecr_image_action_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"
"time"

Expand Down
2 changes: 1 addition & 1 deletion events/ecr_scan_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/ecs_container_instance.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion events/ecs_container_instance_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"
"time"

Expand Down
2 changes: 1 addition & 1 deletion events/epoch_time.go
Expand Up @@ -3,7 +3,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion events/epoch_time_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"
"time"

Expand Down
2 changes: 1 addition & 1 deletion events/firehose_test.go
Expand Up @@ -3,7 +3,7 @@ package events

import (
"context"
"encoding/json"
"github.com/segmentio/encoding/json"
"strings"
"testing"

Expand Down
2 changes: 1 addition & 1 deletion events/iot_1_click_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/iot_button_test.go
Expand Up @@ -2,7 +2,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand Down
2 changes: 1 addition & 1 deletion events/iot_preprovision_hook_test.go
@@ -1,7 +1,7 @@
package events

import (
"encoding/json"
"github.com/segmentio/encoding/json"
"io/ioutil" //nolint: staticcheck
"testing"

Expand Down

0 comments on commit 5ff5739

Please sign in to comment.