Skip to content

Commit

Permalink
Faster metadata parsing (#1385)
Browse files Browse the repository at this point in the history
Benchmarks here:

pulumi/pulumi-aws#2819

Use json-iterator as a drop-in replacement for the stdlib. Should
already be a Pulumi dependency.

It gives a quick speedup for the large AWS use case with very little
effort.

Approximate saving is 300ms.
  • Loading branch information
t0yv0 authored Sep 21, 2023
1 parent e26a663 commit bae6e34
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions unstable/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package metadata

import (
"encoding/json"

"github.com/json-iterator/go"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
)

Expand All @@ -26,7 +26,8 @@ type Data struct{ m map[string]*json.RawMessage }
func New(data []byte) (*Data, error) {
m := map[string]*json.RawMessage{}
if len(data) > 0 {
err := json.Unmarshal(data, &m)
jsoni := jsoniter.ConfigCompatibleWithStandardLibrary
err := jsoni.Unmarshal(data, &m)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -58,7 +59,8 @@ func Set(d *Data, key string, value any) error {
delete(d.m, key)
return nil
}
data, err := json.Marshal(value)
jsoni := jsoniter.ConfigCompatibleWithStandardLibrary
data, err := jsoni.Marshal(value)
if err != nil {
return err
}
Expand All @@ -73,7 +75,8 @@ func Get[T any](d *Data, key string) (T, bool, error) {
if !ok {
return t, false, nil
}
err := json.Unmarshal(*data, &t)
jsoni := jsoniter.ConfigCompatibleWithStandardLibrary
err := jsoni.Unmarshal(*data, &t)
return t, true, err
}

Expand Down

0 comments on commit bae6e34

Please sign in to comment.