[jboss-jira] [JBoss JIRA] (JGRP-1990) Headers: use 1 array rather than 2
Bela Ban (JIRA)
issues at jboss.org
Tue Dec 1 07:12:00 EST 2015
[ https://issues.jboss.org/browse/JGRP-1990?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13135585#comment-13135585 ]
Bela Ban commented on JGRP-1990:
--------------------------------
The memory savings are nice:
{noformat}
org.jgroups.util.Headers object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 4 short[] Headers.ids N/A
16 4 Header[] Headers.hdrs N/A
20 4 (loss due to the next object alignment)
Instance size: 24 bytes (estimated, the sample instance is not available)
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total
{noformat}
A message had a ref to a {{Headers}} instance, which had refs to an {{id}} (carrying the prot-ids) and a {{headers}} array (carrying the actual headers). A {{Headers}} instances takes roughly 24 bytes of memory as shown above. Half of that is the cost of the _object header_ (12 bytes)!
The new message has a ref to a {{Header[]}} array, in which all headers are stored. The {{Header}} abstract superclass now also carries a short which adds 2 bytes to each header.
The advantages of this new approach, which stores headers directly in an array of {{Message}} are:
* Less memory need: the overall cost of maintaining headers (without the cost of the actual headers) is now ~ 24 bytes - 2 bytes = *22 bytes lower* (per message) !
* If the headers array needs to be grown, we only have to grow 1 rather than 2 arrays
> Headers: use 1 array rather than 2
> ----------------------------------
>
> Key: JGRP-1990
> URL: https://issues.jboss.org/browse/JGRP-1990
> Project: JGroups
> Issue Type: Enhancement
> Reporter: Bela Ban
> Assignee: Bela Ban
> Fix For: 3.6.7
>
>
> Currently, {{Headers}} uses 1 array for ids and 1 for the actual headers. Experiment whether joining them into one array makes sense, e.g.:
> {noformat}
> | id-1 | hdr-1 | id-2 | hdr-2 | ... | id-n | hdr-n |
> {noformat}
> This saves 4 bytes (compressed OOPs) for an array ref, plus the overhead of the array itself. Plus, resizing only has to be applied to 1 array.
--
This message was sent by Atlassian JIRA
(v6.4.11#64026)
More information about the jboss-jira
mailing list