Skip to content

kvserver: do lazy map allocations in replicaFlowControl#113150

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
sumeerbhola:flow_allocs
Oct 27, 2023
Merged

kvserver: do lazy map allocations in replicaFlowControl#113150
craig[bot] merged 1 commit intocockroachdb:masterfrom
sumeerbhola:flow_allocs

Conversation

@sumeerbhola
Copy link
Copy Markdown
Collaborator

These methods will typically return empty maps, so we can avoid the allocations.

Informs #111561

Epic: none

Release note: None

@sumeerbhola sumeerbhola requested a review from pav-kv October 26, 2023 15:18
@sumeerbhola sumeerbhola requested a review from a team as a code owner October 26, 2023 15:18
@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 26, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@sumeerbhola sumeerbhola added the backport-23.2.x PAST MAINTENANCE SUPPORT: 23.2 patch releases via ER request only label Oct 26, 2023
Copy link
Copy Markdown
Collaborator

@pav-kv pav-kv left a comment

Choose a reason for hiding this comment

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

Nice simple fix, thanks.

Could also store the maps in replicaFlowControl, and reuse them across the runs. Or, to avoid the sticky overhead, draw them from a sync.Pool and release after use. These strategies are less simple and possibly unnecessary. Feel free to leave a TODO though.

These methods will typically return empty maps, so we can avoid the
allocations.

Informs cockroachdb#111561

Epic: none

Release note: None
Copy link
Copy Markdown
Collaborator Author

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

TFTR!

Could also store the maps in replicaFlowControl, and reuse them across the runs. Or, to avoid the sticky overhead, draw them from a sync.Pool and release after use. These strategies are less simple and possibly unnecessary. Feel free to leave a TODO though.

I've left a comment in replicaFlowControlIntegrationImpl.notActivelyReplicatingTo for one of these possible optimizations. I didn't frame it as a TODO since I suspect we may never need to do it.

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


pkg/kv/kvserver/flow_control_replica.go line 63 at r1 (raw file):

Previously, pavelkalinnikov (Pavel Kalinnikov) wrote…

Could do with a comment why initialization is lazy here. Same below.

Done

@sumeerbhola
Copy link
Copy Markdown
Collaborator Author

test failure is unrelated #113112

Copy link
Copy Markdown
Contributor

@aadityasondhi aadityasondhi left a comment

Choose a reason for hiding this comment

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

thanks for the quick fix!

:lgtm:

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

@sumeerbhola
Copy link
Copy Markdown
Collaborator Author

bors r=pavelkalinnikov,aadityasondhi

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 27, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-23.2.x PAST MAINTENANCE SUPPORT: 23.2 patch releases via ER request only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants