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 io is a dropin replacement that it's faster than the
standard library. In this case is ~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 #381
  • Loading branch information
dcu committed Oct 28, 2023
1 parent c4e28da commit 4319488
Show file tree
Hide file tree
Showing 70 changed files with 89 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cfn/event_test.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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/iot_test.go
Original file line number Diff line number Diff line change
@@ -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/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package events

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

type KafkaEvent struct {
Expand Down
Loading

0 comments on commit 4319488

Please sign in to comment.