inefficient JS calls to marc.field()

Bug #1827954 reported by James Fournie on 2019-05-06
This bug affects 1 person
Affects Status Importance Assigned to Milestone

Bug Description

I ran a JS profiler on the bib record view and found marc.field() is called thousands of times in the bib record view.

The number of calls increases with the number of MARC fields and subfields.

Part of the reason for this is marcedit.js, which is called in the background of the record view, even if the MARC editor is not being loaded.

Within marcedit.js, record.subfield('901','c') is called numerous times for each field, simply to generate HTML ids and class names containing the record's ID

This might not be so bad, except for the fact that marc.subfield calls marc.field, which in turn does a filter on the array of marc fields. Thus for each field, it (multiple times) has to scan each other field in the MARC record, all just to get the ID.

A sample record I tested with here:
This record calls marc.field() 105 times to get the 006, 105 times to get the 008, and 1348 times to get the 901. In total 1559 times. And with the .filter() calls, it means each MARC field was touched 38,775 times. This increases the longer the MARC record.

I'm not sure the solution, but I'd suggest three possible things:

1. cleaning up marcedit.js so it doesn't make so many calls like this in those templates. Again, in some cases this is just generating an HTML id which I don't think is ever referenced again. Or maybe the ID can be injected elsewhere

2. It might also be worthwhile to add a hash (by tag) to marcrecord.js to speed up those calls (although it would need to be updated every time the record is loaded or changes so this could slow things down in other ways)

3. It might be better if marcedit.js wasn't called until that tab is actually accessed. a lot of folks working in libraries never touch the marc editor

tags: added: cleanup
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers