Skip to content

kv/batcheval: replace command hash-map with array#84108

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/cmdMapBatcheval
Jul 12, 2022
Merged

kv/batcheval: replace command hash-map with array#84108
craig[bot] merged 1 commit intocockroachdb:masterfrom
nvb:nvanbenschoten/cmdMapBatcheval

Conversation

@nvb
Copy link
Copy Markdown
Contributor

@nvb nvb commented Jul 8, 2022

The per-request hash-map lookup showed up in CPU profiles while running TPC-E:

----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
                                                0.03s 60.00% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).collectSpans github.com/cockroachdb/cockroach/pkg/kv/kvserver/pkg/kv/kvserver/replica_send.go:1093 (inline)
                                                0.02s 40.00% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.evaluateCommand github.com/cockroachdb/cockroach/pkg/kv/kvserver/pkg/kv/kvserver/replica_evaluate.go:483 (inline)
            0     0%     0%      0.05s 0.029%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval.LookupCommand github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval/command.go:116
                                                0.02s 40.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:57
                                                0.02s 40.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:84
                                                0.01s 20.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:69
----------------------------------------------------------+-------------

It's easy enough to get rid of by replacing the hash-map with an array, like we do in other parts of the code.

@nvb nvb requested a review from aayushshah15 July 8, 2022 21:27
@nvb nvb requested a review from a team as a code owner July 8, 2022 21:27
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@nvb nvb force-pushed the nvanbenschoten/cmdMapBatcheval branch from d9e0201 to 77f1ddd Compare July 9, 2022 19:58
Copy link
Copy Markdown
Contributor

@shralex shralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @aayushshah15 and @nvanbenschoten)


pkg/kv/kvserver/batcheval/declare_test.go line 35 at r1 (raw file):

	for i, command := range cmds {
		method := roachpb.Method(i)

nit: this can be moved after the "if"

@nvb nvb force-pushed the nvanbenschoten/cmdMapBatcheval branch from 77f1ddd to 6015c6b Compare July 12, 2022 03:07
The per-request hash-map lookup showed up in CPU profiles while running
TPC-E:
```
----------------------------------------------------------+-------------
      flat  flat%   sum%        cum   cum%   calls calls% + context
----------------------------------------------------------+-------------
                                                0.03s 60.00% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.(*Replica).collectSpans github.com/cockroachdb/cockroach/pkg/kv/kvserver/pkg/kv/kvserver/replica_send.go:1093 (inline)
                                                0.02s 40.00% |   github.com/cockroachdb/cockroach/pkg/kv/kvserver.evaluateCommand github.com/cockroachdb/cockroach/pkg/kv/kvserver/pkg/kv/kvserver/replica_evaluate.go:483 (inline)
            0     0%     0%      0.05s 0.029%                | github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval.LookupCommand github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval/command.go:116
                                                0.02s 40.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:57
                                                0.02s 40.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:84
                                                0.01s 20.00% |   runtime.mapaccess2_fast64 GOROOT/src/runtime/map_fast64.go:69
----------------------------------------------------------+-------------
```

It's easy enough to get rid of by replacing the hash-map with
an array, like we do in other parts of the code.
@nvb nvb force-pushed the nvanbenschoten/cmdMapBatcheval branch from 6015c6b to 4a9816b Compare July 12, 2022 03:08
Copy link
Copy Markdown
Contributor Author

@nvb nvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTRs!

bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @shralex)


pkg/kv/kvserver/batcheval/declare_test.go line 35 at r1 (raw file):

Previously, shralex wrote…

nit: this can be moved after the "if"

Done.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jul 12, 2022

Build succeeded:

@craig craig bot merged commit 571bfa3 into cockroachdb:master Jul 12, 2022
@nvb nvb deleted the nvanbenschoten/cmdMapBatcheval branch July 12, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants