Value compaction seems to do a lot of unnecessary work
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 106
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
While I was implementing value compaction as per https://www.w3.org/TR/json-ld11-api/#value-compaction there seems to be some unnecessary work being performed.
Steps 2 and 3 are unnecessary, the inverse context is never used during value compaction. I assume this is a left-over from a previous draft of the spec?
Compact value is only ever called once during Compaction, in step 7:
If element has an
@valueor@identry and the result of using the Value Compaction algorithm, passing active context, active property, and element as value is a scalar, or the term definition for active property has a type mapping of@json, return that result.
With the exception of the @json entry, the result from value compaction is always discarded if it's not a scalar. This would suggest that every step in Value Compaction where we return anything other than a scalar is not necessary. For a value that's @json, we don't want to perform IRI compaction of the keys as far as I understand it, which would also make step 11 in value compaction unnecessary. I might be wrong about this part. Since we only ever care for the scalar return, creating the copy of result in step 1 isn't necessary either.
It seems like we can simplify things by:
- In Compaction step 7:
- First check if the type mapping is
@jsonand return value without going through Value Compaction. - Then do the value compaction and return it if it's not
null.
- First check if the type mapping is
- Update the Value Compaction as follows:
- Drop 1), 2), 3).
- In step 8) keep the branch but do nothing.
- Drop 11).
- Update 12) to return
null
These changes seem to work in my own processor without it causing anything in the compaction test suite to fail.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JSON-LD 1.1 Compaction and Value Compaction algorithms described in the issue, then run the compaction test suite. Verify that the proposed simplification preserves scalar results and @json behavior; done means the changes pass the suite without altering required compaction results.
Written by the indexing model from the issue text.
Assessment
- Domain
- documentation
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100