[Notes] [Git][BuildStream/buildstream][danielsilverstone-ct/further-optimisations] 2 commits: _yaml.py: Reduce cost of node_final_assertions



Title: GitLab

Daniel Silverstone pushed to branch danielsilverstone-ct/further-optimisations at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_context.py
    ... ... @@ -361,14 +361,17 @@ class Context():
    361 361
         #    (bool): Whether or not to use strict build plan
    
    362 362
         #
    
    363 363
         def get_strict(self):
    
    364
    +        if self._strict_build_plan is None:
    
    365
    +            # Either we're not overridden or we've never worked it out before
    
    366
    +            # so work out if we should be strict, and then cache the result
    
    367
    +            toplevel = self.get_toplevel_project()
    
    368
    +            overrides = self.get_overrides(toplevel.name)
    
    369
    +            self._strict_build_plan = _yaml.node_get(overrides, bool, 'strict', default_value=True)
    
    364 370
     
    
    365 371
             # If it was set by the CLI, it overrides any config
    
    366
    -        if self._strict_build_plan is not None:
    
    367
    -            return self._strict_build_plan
    
    368
    -
    
    369
    -        toplevel = self.get_toplevel_project()
    
    370
    -        overrides = self.get_overrides(toplevel.name)
    
    371
    -        return _yaml.node_get(overrides, bool, 'strict', default_value=True)
    
    372
    +        # Ditto if we've already computed this, then we return the computed
    
    373
    +        # value which we cache here too.
    
    374
    +        return self._strict_build_plan
    
    372 375
     
    
    373 376
         # get_cache_key():
    
    374 377
         #
    

  • buildstream/_yaml.py
    ... ... @@ -1109,6 +1109,10 @@ __LIST_TYPES = (list, yaml.comments.CommentedSeq)
    1109 1109
     # copying tactic.
    
    1110 1110
     __PROVENANCE_TYPES = (Provenance, DictProvenance, MemberProvenance, ElementProvenance)
    
    1111 1111
     
    
    1112
    +# These are the directives used to compose lists, we need this because it's
    
    1113
    +# slightly faster during the node_final_assertions checks
    
    1114
    +__NODE_ASSERT_COMPOSITION_DIRECTIVES = ('(>)', '(<)', '(=)')
    
    1115
    +
    
    1112 1116
     
    
    1113 1117
     def node_chain_copy(source):
    
    1114 1118
         copy = ChainMap({}, source)
    
    ... ... @@ -1202,22 +1206,26 @@ def node_final_assertions(node):
    1202 1206
             # indicates that the user intended to override a list which
    
    1203 1207
             # never existed in the underlying data
    
    1204 1208
             #
    
    1205
    -        if key in ['(>)', '(<)', '(=)']:
    
    1209
    +        if key in __NODE_ASSERT_COMPOSITION_DIRECTIVES:
    
    1206 1210
                 provenance = node_get_provenance(node, key)
    
    1207 1211
                 raise LoadError(LoadErrorReason.TRAILING_LIST_DIRECTIVE,
    
    1208 1212
                                 "{}: Attempt to override non-existing list".format(provenance))
    
    1209 1213
     
    
    1210
    -        if isinstance(value, collections.abc.Mapping):
    
    1214
    +        value_type = type(value)
    
    1215
    +
    
    1216
    +        if value_type in __DICT_TYPES:
    
    1211 1217
                 node_final_assertions(value)
    
    1212
    -        elif isinstance(value, list):
    
    1218
    +        elif value_type in __LIST_TYPES:
    
    1213 1219
                 list_final_assertions(value)
    
    1214 1220
     
    
    1215 1221
     
    
    1216 1222
     def list_final_assertions(values):
    
    1217 1223
         for value in values:
    
    1218
    -        if isinstance(value, collections.abc.Mapping):
    
    1224
    +        value_type = type(value)
    
    1225
    +
    
    1226
    +        if value_type in __DICT_TYPES:
    
    1219 1227
                 node_final_assertions(value)
    
    1220
    -        elif isinstance(value, list):
    
    1228
    +        elif value_type in __LIST_TYPES:
    
    1221 1229
                 list_final_assertions(value)
    
    1222 1230
     
    
    1223 1231
     
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]