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

Reduce the size of the MessageID structs by one word on 64-bit arch #316

Merged
merged 1 commit into from
Jul 8, 2020

Conversation

dferstay
Copy link
Contributor

@dferstay dferstay commented Jul 8, 2020

An int occupies one word of memory; on 64-bit machines, this is 8 bytes.

As a result, the messageID struct is 56-bytes:

  • ledgerID - 8 bytes
  • entryID - 8 bytes
  • batchIdx - 8 bytes
  • partitionIdx - 8 bytes
  • tracker - 8 bytes
  • consumer - 16 bytes (1 word for type, 1 word for data address)

This commit changes the type of batchIdx and partitionIdx fields to int32,
which saves one word of memory and maintains alignment of struct fields.

Reducing the size of the MessageID structs is important as they are
currently allocated on the heap for every message produced or consumed.

Signed-off-by: Daniel Ferstay dferstay@splunk.com

Motivation

The motivation is to reduce the amount of heap allocated memory for each message produced and consumed.

Modifications

This commit changes the type batchIdx and partitionIdx fields to int32,
which saves one word of memory and maintains alignment of struct fields.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests that produce or consume messages.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no

Documentation

  • Does this pull request introduce a new feature? no

@merlimat merlimat added this to the 0.2.0 milestone Jul 8, 2020
An int occupies one word of memory; on 64-bit machines, this is 8 bytes.

As a result, the messageID struct is 56-bytes:
* ledgerID - 8 bytes
* entryID - 8 bytes
* batchIdx - 8 bytes
* partitionIdx - 8 bytes
* tracker - 8 bytes
* consumer - 16 bytes (1 word for type, 1 word for data address)

This commit changes the type of batchIdx and partitionIdx fields to int32
which saves one word of memory and maintains alignment of struct fields.

Reducing the size of the MessageID structs is important as they are
currently allocated on the heap for every message produced or consumed.

Signed-off-by: Daniel Ferstay <dferstay@splunk.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants