Skip to content

Commit

Permalink
server: Remove an unnecessary AST-to-JSON conversion for the eval input.
Browse files Browse the repository at this point in the history
The cost of this can become non-trivial with larger inputs.

Signed-off-by: Teemu Koponen <koponen@styra.com>
  • Loading branch information
koponen-styra authored and ashutosh-narkar committed Apr 3, 2024
1 parent 9a13941 commit 27d6829
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ func (s *Server) instrumentHandler(handler func(http.ResponseWriter, *http.Reque
return httpHandler
}

func (s *Server) execQuery(ctx context.Context, br bundleRevisions, txn storage.Transaction, parsedQuery ast.Body, input ast.Value, m metrics.Metrics, explainMode types.ExplainModeV1, includeMetrics, includeInstrumentation, pretty bool) (*types.QueryResponseV1, error) {
func (s *Server) execQuery(ctx context.Context, br bundleRevisions, txn storage.Transaction, parsedQuery ast.Body, input ast.Value, rawInput *interface{}, m metrics.Metrics, explainMode types.ExplainModeV1, includeMetrics, includeInstrumentation, pretty bool) (*types.QueryResponseV1, error) {
results := types.QueryResponseV1{}
logger := s.getDecisionLogger(br)

Expand All @@ -893,15 +893,6 @@ func (s *Server) execQuery(ctx context.Context, br bundleRevisions, txn storage.
buf = topdown.NewBufferTracer()
}

var rawInput *interface{}
if input != nil {
x, err := ast.JSON(input)
if err != nil {
return nil, err
}
rawInput = &x
}

var ndbCache builtins.NDBCache
if s.ndbCacheEnabled {
ndbCache = builtins.NDBCache{}
Expand Down Expand Up @@ -2277,7 +2268,7 @@ func (s *Server) v1QueryGet(w http.ResponseWriter, r *http.Request) {
return
}
pretty := pretty(r)
results, err := s.execQuery(ctx, br, txn, parsedQuery, nil, m, explainMode, includeMetrics(r), includeInstrumentation, pretty)
results, err := s.execQuery(ctx, br, txn, parsedQuery, nil, nil, m, explainMode, includeMetrics(r), includeInstrumentation, pretty)
if err != nil {
switch err := err.(type) {
case ast.Errors:
Expand Down Expand Up @@ -2347,7 +2338,7 @@ func (s *Server) v1QueryPost(w http.ResponseWriter, r *http.Request) {
return
}

results, err := s.execQuery(ctx, br, txn, parsedQuery, input, m, explainMode, includeMetrics, includeInstrumentation, pretty)
results, err := s.execQuery(ctx, br, txn, parsedQuery, input, request.Input, m, explainMode, includeMetrics, includeInstrumentation, pretty)
if err != nil {
switch err := err.(type) {
case ast.Errors:
Expand Down

0 comments on commit 27d6829

Please sign in to comment.