[YANGTOOLS-1076] Trim down SchemaPath size Created: 22/Jan/20  Updated: 12/Feb/20  Resolved: 12/Feb/20

Status: Resolved
Project: yangtools
Component/s: parser
Affects Version/s: None
Fix Version/s: 5.0.0

Type: Story Priority: Medium
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Blocks
is blocked by YANGTOOLS-761 Remove SchemaNode hashCode()/equals() Resolved
Epic Link: Get rid of SchemaNode.getPath()

 Description   

Current layout of SchemaPath favors instantiation of temporary paths and their retention in the object, which means we will end up eating up memory even after we have completed all that is needed. Furthermore we are caching hashCode in the SchemaPath object.

This results in the following layout:

***** 32-bit VM: **********************************************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0     8                                                        (object header)                           N/A
      8     4                                                    int SchemaPath.hash                           N/A
     12     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     16     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     20     4                com.google.common.collect.ImmutableList SchemaPath.legacyPath                     N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

***** 64-bit VM: **********************************************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    16                                                        (object header)                           N/A
     16     4                                                    int SchemaPath.hash                           N/A
     20     4                                                        (alignment/padding gap)                  
     24     8   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     32     8           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     40     8                com.google.common.collect.ImmutableList SchemaPath.legacyPath                     N/A
Instance size: 48 bytes
Space losses: 4 bytes internal + 0 bytes external = 4 bytes total

***** 64-bit VM, compressed references enabled: ***************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    12                                                        (object header)                           N/A
     12     4                                                    int SchemaPath.hash                           N/A
     16     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     20     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     24     4                com.google.common.collect.ImmutableList SchemaPath.legacyPath                     N/A
     28     4                                                        (loss due to the next object alignment)
Instance size: 32 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

***** 64-bit VM, compressed references enabled, 16-byte align: ************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    12                                                        (object header)                           N/A
     12     4                                                    int SchemaPath.hash                           N/A
     16     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     20     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     24     4                com.google.common.collect.ImmutableList SchemaPath.legacyPath                     N/A
     28     4                                                        (loss due to the next object alignment)
Instance size: 32 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

Losing either hash code or the legacy path would improve the situation by 16-25%, making SchemaContext a tad smaller.



 Comments   
Comment by Robert Varga [ 22/Jan/20 ]

SchemaNodes relying on hashCode()/equals() could ruin our efficiency here.

Comment by Robert Varga [ 22/Jan/20 ]

For legacyPath we can most probably create some sort of backwards/forwards collection, similar to what we are doing for PathArguments in YangInstanceIdentifier. The hashCode cache can probably go, as we do not really expect it to be looked up anymore – aside from UsesNode, which will need to be taught some other trick to track its refines.

Comment by Robert Varga [ 12/Feb/20 ]

The resulting layout looks like this:

***** 32-bit VM: **********************************************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0     8                                                        (object header)                           N/A
      8     4                                                    int SchemaPath.hash                           N/A
     12     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     16     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     20     4                                                        (loss due to the next object alignment)
Instance size: 24 bytes
Space losses: 0 bytes internal + 4 bytes external = 4 bytes total

***** 64-bit VM: **********************************************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    16                                                        (object header)                           N/A
     16     4                                                    int SchemaPath.hash                           N/A
     20     4                                                        (alignment/padding gap)                  
     24     8   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     32     8           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
Instance size: 40 bytes
Space losses: 4 bytes internal + 0 bytes external = 4 bytes total

***** 64-bit VM, compressed references enabled: ***************************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    12                                                        (object header)                           N/A
     12     4                                                    int SchemaPath.hash                           N/A
     16     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     20     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
Instance size: 24 bytes
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total

***** 64-bit VM, compressed references enabled, 16-byte align: ************
org.opendaylight.yangtools.yang.model.api.SchemaPath object internals:
 OFFSET  SIZE                                                   TYPE DESCRIPTION                               VALUE
      0    12                                                        (object header)                           N/A
     12     4                                                    int SchemaPath.hash                           N/A
     16     4   org.opendaylight.yangtools.yang.model.api.SchemaPath SchemaPath.parent                         N/A
     20     4           org.opendaylight.yangtools.yang.common.QName SchemaPath.qname                          N/A
     24     8                                                        (loss due to the next object alignment)
Instance size: 32 bytes
Space losses: 0 bytes internal + 8 bytes external = 8 bytes total

 

Generated at Wed Feb 07 20:55:07 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.