[YANGTOOLS-854] Expose statefulness of SourceSpecificContext to StatementStreamSource Created: 26/Feb/18  Updated: 27/Feb/18  Resolved: 27/Feb/18

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

Type: Improvement Priority: High
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-713 Make YangStatementParserListenerImpl ... Resolved

 Description   

The decoupling of spi.source.StatementStreamSource (source), spi.source.StatementWriter (glue interface) and reactor.SourceSpecificContext (reused receiver) is a sound one from API/implementation decoupling, but given we iterate through each source four times (pre-linkage, linkage, statement definition, full definition), StatementStreamSource implementations end up processing statements multiple times.

For each such statement, there are multiple lookups/allocations going on:

  • statement name
  • statement argument
  • statement definition
  • statement source reference

before we dispatch to StatementWriter.startStatement(), which in turn dispatches to SourceSpecificContext.createDeclaredChild(), which ends up not using these objects at all and returns an existing object.

There are situations where a statement can be fully defined in statement definition phase, in which case they can be completely skipped in StatementStreamSource and processed by SourceSpecificContext (or StatementContextWriter), as it already has a full and accurate view of the statement contents, including all substatements.

StatementStreamSource and SourceSpecificContext already have a way of uniquely identifying statements – which is their offset at their nesting level. It is a simple int assigned by StatementStreamSource, which does not require any heavy lifting on StatementStreamSource's part and requires only simple (potentially recursive) lookup on SourceSpecificContext's part (which is already done anyway).

Using this glue identifier it should be possible to communicate above four bits of information from SourceSpecificContext back to StatementStreamSource, such that it can reuse this information without incurring repetitive work. Fully-defined statements can be marked as such if StatementStreamSource has not skipped any unknown statements during recursive walk of children in SourceSpecificContext when StatementStreamSource invokes StatementWriter.endStatement().

If we design a walk protocol with this communication in place, we can:

  • skip statement lookups in StatementStreamSource
  • completely offload phase processing of already-fully-defined statements to SourceSpecificContext/StatementContextWriter

This will lead to more CPU/memory efficient statement streaming, especially during full statement definition phase.



 Comments   
Comment by Robert Varga [ 27/Feb/18 ]

https://git.opendaylight.org/gerrit/68811 infrastructure and YangStatementStream conversion

https://git.opendaylight.org/gerrit/68814 YinStatementStream conversion

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