sul-dlss / cocina-models

Cocina repository data model (implemented in Ruby)
https://sul-dlss.github.io/cocina-models/
3 stars 0 forks source link

improve efficiency of object type detection #537

Closed peetucket closed 1 year ago

peetucket commented 1 year ago

Why was this change made? 🤔

Part of https://github.com/sul-dlss/common-accessioning/issues/1005, which is timeouts on a large object.

Experimentation as shown in that ticket has demonstrated that for very large cocina objects (which in DSA are manipulated as in memory hashes), the detection of object type may not be very efficient due to the use of both the rails method with_indifferent_access (this makes a full copy of the giant hash in memory and returns a new object) and fetch (also possibly makes a copy of the hash based on console output). Neither of these are really necessary, we can simply inspect the hash directly for the key and raise as needed.

While I did not characterize the actual performance/memory improvements achieved by this refactor (may only be a few seconds even for very large object), this method is also well tested, so seems low risk.

How was this change tested? 🤨

Existing specs (which cover this method well).

mjgiarlo commented 1 year ago

Thanks, @peetucket!