[YANGTOOLS-1497] Improve NamespaceBehaviour/NamespaceStorageNode interactions Created: 05/Apr/23  Updated: 06/Apr/23  Resolved: 06/Apr/23

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

Type: Improvement Priority: High
Reporter: Robert Varga Assignee: Robert Varga
Resolution: Done Votes: 0
Labels: pt
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Issue Links:
Blocks
blocks YANGTOOLS-1503 Disconnect NamespaceStmtCtx from Curr... Resolved
Relates
relates to YANGTOOLS-1204 Do not subclass NamespaceBehaviour in... Resolved
Sub-Tasks:
Key
Summary
Type
Status
Assignee
YANGTOOLS-1498 Disconnect StatementContextBundle fro... Sub-task Resolved Robert Varga  
YANGTOOLS-1499 Remove NamespaceBehaviour.Registry Sub-task Resolved Robert Varga  
YANGTOOLS-1501 NamespaceBehaviour should not be Iden... Sub-task Resolved Robert Varga  
YANGTOOLS-1500 Separate NamespaceBehaviour and Names... Sub-task Resolved Robert Varga  
Epic Link: Parser Performance

 Description   

As examined in YANGTOOLS-1159, YANGTOOLS-1204 and other places, we spend a significant amount of time traversing the NamespaceStorageNode tree towards root in order to find things that are shared either on source-local, module-local or global scope.

At the end of the day, for any ParserNamespace operation, we have to find its NamespaceBehaviour and then execute the request using that behaviour.

There is a connection between these operations, at least in the yang-parser-reactor implementation. The story goes something like this:

  1. there are 4 StorageNodeTypes
  2. we have a single baseline NamespaceStorageNode implementation (NamespaceStorageSupport), which is subclassed
  3. there is the notion of NamespaceBehaviour.Registry, of which we have three implementations:
    1. BuildGlobalContext, which also is the only StorageNodeType.GLOBAL
    2. SourceSpecificContext, which also is the only StorageNodeType.SOURCE_LOCAL_SPECIAL
    3. StatementSupportBundle, which seems to be quite unrelated to this problem, but has interaction with BuildGlobalContext
  4. StorageNodeType.ROOT_STATEMENT_LOCAL is only implemented by RootStatementContext
  5. StorageNodeType.STATEMENT_LOCAL by all other ReactorStmtCtx subclasses

The behaviour count breaks down as follows:

  1. global() has 19 references (GLOBAL node)
  2. sourceLocal() has 6 references (SOURCE_LOCAL_SPECIAL node)
  3. statementLocal() has 7 references (STATEMENT_LOCAL node)
  4. rootStatementLocal() has 3 references (ROOT_STATEMENT_LOCAL node)
  5. treeScoped() has 2 references (which means the first match node along ancestor axis)

The yang-parser-reactor implementation essentially requires a walk to BuildGlobalContext to acquire NamespaceBehaviours, which it wraps with extended implementations (Simple/VirtualNamespaceContext) – hence these implementations are primed to have a quick way to access the GLOBAL node. Furthermore RootStatementContext has a direct pointer to SourceSpecificContext and that has a direct pointer to BuildGlobalContext.

Based on these implementation specifics, there seems to be an opportunity to knock off at least the global() case in that we would memoize BuildGlobalContext reference in NamespaceContexts – and then we just need to provide a mechanism for them to provide access to it to their respective NamespaceBehaviours.

This will provide immediate benefits to major users:

  1. SUPPORTED_FEATURES, which is behind ReactorStmtCtx.isSupportedByFeatures()
  2. FEATURE, which does the the same
  3. MODULECTX_TO_QNAME, which participates on local QName construction

as these will not have to walk the statement tree again to reach BuildGlobalContext.

While there may be other opportunities, this issue should focus on:

  1. disconnecting StatementSupportBundle and NamespaceBehaviour.Registry
  2. perhaps making NamespaceBehaviour.Registry a yang-parser-reactor-internal thing
  3. providing a way for NamespaceBehaviour.global() to receive BuildGlobalContext reference without traversing NamespaceStorageNode tree

 



 Comments   
Comment by Robert Varga [ 06/Apr/23 ]

YANGTOOLS-1204 is part of the picture here, as that revolves around yang-parser-reactor's coupling to NamespaceBehaviour. Once we have addressed it we have a convenient place where we can store the reference to BuildGlobalContext.

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