Repository navigation
perf: record construction, unified() and add_namespace get faster, with output unchanged (3.3.0 spec 4, PR 24b) - #699
Merged
Merged
Conversation
…n test only when a single-valued attribute repeats, so an attribute name whose __eq__ raises no longer raises before anything is stored (spec 4, T1.2)
…ypes, scans a call's attributes for prov:collection only when a single-valued attribute repeats, and returns a resolved qualified name without the datetime and None checks it can never fail; output is unchanged (spec 4, T1.2)
…a record's merge no longer hashes and compares the record; every copy of an equal record still merges (spec 4, T1.6)
… instead of scanning every namespace, so declaring many namespaces takes linear time; the result is unchanged (spec 4, T1.7)
…ibutes for prov:collection at most once, after the first repeat of a single-valued attribute, so a document repeating one many times reads in linear time; spec 4 says so and states S15 in plain sentences, and two cosmetic fixes in add_namespace and its test (spec 4, T1.2, T1.7)
…on scan and a helper compares and raises, a qualified name's None check sits in its branch, a test pins one scan per call, and spec 4 states S15 in sections 1 and 4, names the function A3 changes and what 24b pins (spec 4, T1.2, T1.7)
…ult in each branch, a comment that no longer held goes, the membership test names its three cases with one parameter, and the namespace test reuses its renamed namespace (spec 4, T1.2, T1.7)
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 5 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
… as its docstring says, instead of the argument; spec 4 records the ruling as S16 (spec 4, T1.7) The two namespaces are equal, so no output changes. Names minted from the returned namespace now take _reconcile_qualified_name's identity shortcut.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three speed changes to the model from the 3.3.0 performance spec (spec 4, section 3.2), with every output, error and warning unchanged except one case spec 4 rules on (S15). Against
main,unifiedis 22.7% faster,construct12.5%,prov_to_graph11.9%,deserialize[json]7.2%,deserialize[jsonld]6.9% anddeserialize[xml]5.5%, and every other benchmark case is within −2.7% and +0.6%._value_keytestsIdentifierfirst, since identifiers are the commonest attribute value and the type subclasses none of the others.add_attributesscans a call's attributes forprov:collectiononly when a single-valued attribute repeats, at most once per call, where it used to scan every call up front. A resolved qualified name is returned without thedatetimeandNonechecks it can never fail. The repeated-value comparison moves into a small helper,_check_repeated_value.unified(). The merge map is keyed by each record'sid(), so finding a record's merge no longer hashes and compares the whole record. Every copy of an equal record still merges, including two equal copies sharing an identifier with a third record.add_namespace. An equal registered namespace is found by one lookup under its prefix instead of a scan of every namespace, so declaring many namespaces takes linear time (8,000 namespaces: 1.75 s onmain, 0.01 s here). For an equal namespace it now returns the registered namespace, as its docstring says, rather than the argument; the two are equal (S16).S15: on
main,add_attributescompared every attribute name withprov:collectionbefore storing anything, so a name object whose__eq__raises made the call raise up front. It now raises only when a single-valued attribute repeats. Names from the readers and the API are strings or qualified names, so nothing they accept changes.Why: these are the model-side changes the performance study measured as behaviour-free, after the writer-side changes of #698.
How it was checked: the output-identity script reads every fixture under
src/prov/testsand writes the benchmark document, the example documents and every fixture document in each format. It then reads each one back and comparesunified(),flattened(), document equality andprov_to_dotagainstmainunderPYTHONHASHSEED1 and 2, and finds no difference. A probe also confirmed that a document repeating one formal attribute thousands of times reads as fast as onmain(8,000 repeatedprov:activityelements in PROV-XML: 0.024 s on both). New cases pin theprov:collectionrule with the collection after the repeat and with a one-shot iterator, a single scan per call, two equal copies plus a third record merging into one, andadd_namespacereturning the registered namespace for an equal one without registering anything. Spec 4 records S15, S16 and the wording this PR needed. No HISTORY entry, since output is unchanged andadd_namespacenow returns what its docstring promised.