[YANGTOOLS-166] Generated builder cpu/memory efficiency Created: 16/May/14 Updated: 10/Apr/22 Due: 20/May/14 Resolved: 16/May/14 |
|
| Status: | Resolved |
| Project: | yangtools |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | ||
| Reporter: | Robert Varga | Assignee: | Martin Vitez |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Operating System: All |
||
| Description |
|
The builders we generate are not entirely memory/cpu efficient. Specifically the way augmentations are retained is sub-optimal, creating undue pressure. A typical object looks like this: private static final class TlvsImpl implements Tlvs { public Class<org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs> getImplementedInterface() { return org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.Tlvs.class; } private final OfList _ofList; private TlvsImpl(TlvsBuilder builder) { this._ofList = builder.getOfList(); this.augmentation.putAll(builder.augmentation); }Note how "augmentation" allocation is disconnected from the actually filling – this potentially inefficient. So move the allocation from field to constructor, so we can size the map appropriately. Second, most of augmentation instances end up being empty or only a few entries. So check for these circumstances and allocate optimized versions of these maps: switch (builder.augmentation.size()) { This change is API-safe and should be applied to hydrogen/stable as well. |
| Comments |
| Comment by Martin Vitez [ 16/May/14 ] |
|
Proposed patch: |