diff --git a/changelog/Fibonacci747_perf.md b/changelog/Fibonacci747_perf.md new file mode 100644 index 000000000000..fe15648115b4 --- /dev/null +++ b/changelog/Fibonacci747_perf.md @@ -0,0 +1,3 @@ +### Changed + +- avoid string copy when importing slashing protection JSON [#16081](https://github.com/OffchainLabs/prysm/pull/16081) diff --git a/validator/rpc/handlers_slashing.go b/validator/rpc/handlers_slashing.go index 2d8002e297b0..b6545f1c619d 100644 --- a/validator/rpc/handlers_slashing.go +++ b/validator/rpc/handlers_slashing.go @@ -1,10 +1,10 @@ package rpc import ( - "bytes" "encoding/json" "io" "net/http" + "strings" "github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace" "github.com/OffchainLabs/prysm/v7/network/httputil" @@ -74,9 +74,8 @@ func (s *Server) ImportSlashingProtection(w http.ResponseWriter, r *http.Request httputil.HandleError(w, "empty slashing_protection_json specified", http.StatusBadRequest) return } - enc := []byte(req.SlashingProtectionJson) - buf := bytes.NewBuffer(enc) - if err := s.db.ImportStandardProtectionJSON(ctx, buf); err != nil { + rdr := strings.NewReader(req.SlashingProtectionJson) + if err := s.db.ImportStandardProtectionJSON(ctx, rdr); err != nil { httputil.HandleError(w, errors.Wrap(err, "could not import slashing protection history").Error(), http.StatusInternalServerError) return }