Skip to content

Commit

Permalink
Optimization of fastJsonNode
Browse files Browse the repository at this point in the history
`fastJsonNode` is strongly refactored and optimized. Code is simpler, consumes less memory and executes faster.

Changes:
 - slices used instead of maps
 - unified `attrs` and `children` containers into one (`attrs`), removed fastJsonAttr type
 - (min-)heap used instead of sorting
 - much simplified processing (because of single container in `fastJsonNode`)

Performance comparison - artificial test (committed to `query/outputnode_test.go`), times measured without profiler. Memory measured (for entire test execution, including all setup) with default profiler configuration (because `-memprofilerate=1` was much too slow).

| Branch        | `master` | `improve/encode_meomry` | Improvement |
|------- -------|----------|-------------------------|-------------|
| Time:         | 172.283s | 0.336s                  | > 512 x     |
| Total memory" | 43.65GB  | 283.30MB                | > 157 x     |

In fact, memory improvement for encode function is much bigger - encode doesn't allocate memory. `fastJsonNode` creation is also much cheaper (in terms of memory).

This commit resolves #982, resolves #1138 and closes #1227.
  • Loading branch information
Tomasz Zdybał committed Jul 24, 2017
1 parent 95beb26 commit 5efbe7d
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 107 deletions.
5 changes: 4 additions & 1 deletion query/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ func defaultContext() context.Context {
}

func processToFastJsonReq(t *testing.T, query string) (string, error) {
return processToFastJsonReqCtx(t, query, defaultContext())
}

func processToFastJsonReqCtx(t *testing.T, query string, ctx context.Context) (string, error) {
res, err := gql.Parse(gql.Request{Str: query, Http: true})
if err != nil {
return "", err
}
ctx := defaultContext()
queryRequest := QueryRequest{Latency: &Latency{}, GqlQuery: &res}
err = queryRequest.ProcessQuery(ctx)
if err != nil {
Expand Down
Loading

0 comments on commit 5efbe7d

Please sign in to comment.