Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-854

Expose statefulness of SourceSpecificContext to StatementStreamSource

    XMLWordPrintable

Details

    • Improvement
    • Status: Resolved
    • High
    • Resolution: Done
    • None
    • 2.0.2
    • parser
    • None

    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.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              rovarga Robert Varga
              rovarga Robert Varga
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: