Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kv/rangefeed: reduce size of event struct from 200 bytes to 72 bytes #88308

Merged

Conversation

nvanbenschoten
Copy link
Member

This commit restructures the event struct and reduces its size from 200 bytes to 72 bytes. This is accomplished primarily by pushing large, infrequently used struct fields into pointers. This is mostly just a drive-by cleanup found while working on #77724.

Release justification: None. Don't merge yet.

Release note: None.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

Reviewed 2 of 2 files at r1, 4 of 4 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/kv/kvserver/rangefeed/processor.go line 164 at r1 (raw file):

type ctEvent struct {
	hlc.Timestamp

nit: why not type ctEvent hlc.Timestamp?


pkg/kv/kvserver/rangefeed/processor.go line 177 at r1 (raw file):

type syncEvent struct {
	c chan struct{}
	// This setting is used in conjunction with syncC in tests in order to ensure

nit: update to refer to c rather than syncC.

This commit restructures the event struct and reduces its size from 200
bytes to 72 bytes. This is accomplished primarily by pushing large,
infrequently used struct fields into pointers. This is mostly just a
drive-by cleanup.

Release justification: None. Don't merge yet.

Release note: None.
Slight style nit that makes the code less noisy.
Copy link
Member Author

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

TFTR!

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


pkg/kv/kvserver/rangefeed/processor.go line 164 at r1 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

nit: why not type ctEvent hlc.Timestamp?

That's what I had initially, but type ctEvent hlc.Timestamp does not inherit methods while embedding the timestamp does, so this made some code less verbose.

For instance, this allows:

	case !e.ct.IsEmpty():
		p.forwardClosedTS(ctx, e.ct.Timestamp)

instead of:

	case !hlc.Timestamp(e.ct).IsEmpty():
		p.forwardClosedTS(ctx, hlc.Timestamp(e.ct))

Happy to change it if you feel strongly though.


pkg/kv/kvserver/rangefeed/processor.go line 177 at r1 (raw file):

Previously, erikgrinaker (Erik Grinaker) wrote…

nit: update to refer to c rather than syncC.

Done.

Copy link
Contributor

@erikgrinaker erikgrinaker left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r3, 4 of 4 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @nvanbenschoten)


pkg/kv/kvserver/rangefeed/processor.go line 164 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

That's what I had initially, but type ctEvent hlc.Timestamp does not inherit methods while embedding the timestamp does, so this made some code less verbose.

For instance, this allows:

	case !e.ct.IsEmpty():
		p.forwardClosedTS(ctx, e.ct.Timestamp)

instead of:

	case !hlc.Timestamp(e.ct).IsEmpty():
		p.forwardClosedTS(ctx, hlc.Timestamp(e.ct))

Happy to change it if you feel strongly though.

Not at all, this is fine.

@nvanbenschoten nvanbenschoten changed the title kv/rangefeed: reduce size of event struct from 200 bytes to 72 bytes. kv/rangefeed: reduce size of event struct from 200 bytes to 72 bytes Sep 22, 2022
@nvanbenschoten
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Sep 22, 2022

Build succeeded:

@craig craig bot merged commit f08a1b0 into cockroachdb:master Sep 22, 2022
@nvanbenschoten nvanbenschoten deleted the nvanbenschoten/rangefeedEventSize branch September 22, 2022 16:27
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.

None yet

3 participants