FHIR / sushi

SUSHI (aka "SUSHI Unshortens Short Hand Inputs") is a reference implementation command-line interpreter/compiler for FHIR Shorthand (FSH).
Apache License 2.0
145 stars 44 forks source link

Add optional argument for making clone of predefined resources #1500

Closed mint-thompson closed 1 month ago

mint-thompson commented 2 months ago

This PR applies to task CIMPL-1250.

The FHIRDefinitions class provides a public method to return all predefined resources. Hypothetically, the caller of this method could alter the predefined resources, which is why it could be useful to return a clone of these resources. However, in all places this method is called by SUSHI, the resources are used for a search, not for any modifications. By not cloning the resources for the search, significant time savings are possible. Just in case someone else is using SUSHI as a dependency and calling this method and expecting to receive a clone, the default behavior is to return a clone.

When searching for slices, the slice of an element is always a sibling of that element. Therefore, it is preferable to search the smaller list containing only the element's parent's children, when possible. This takes advantage of the underlying ElementDefinition tree. Because the root element's parent is undefined, use the full element list when working with the root element. This shouldn't be possible in most cases, as revealed by the test coverage, but the implementation is defensive just in case something unusual has happened to the root element.

A regression test of public FSH projects updated within the last year indicated no changes. The initial test run indicated changes in two repos, but both of those repos produced identical results in a second run without any code changes. The changes to allPredefinedResources are most visible in projects with many StructureDefinitions. The changes to ElementDefinition are most visible in projects with many Instance definitions. The impact of the ElementDefinition changes is relatively small, but the allPredefinedResources changes are significant for some FSH projects.

The regression test results summary is attached as html. Three projects showed increased run times, but all of those projects are relatively small, with the longest run time being 61 seconds. Some larger projects showed meaningful decreases in run time. As a few examples:

While these are just a few examples I've picked out, and not every project has changes that are so dramatic, I think the overall effect is meaningfully positive without adding an odious amount of complexity to the implementation.

Regression summary HTML