[Maya] Unloading reference really slow in script

I have a script where I reference in a file, transfer some data from the reference to the nodes in the scene, and then unreference the file. I noticed that the script was running slowly. Depending on the scenes I used, it would hang for anywhere from 44 to 128 seconds. After some digging, I figured out that it stalls on the line:

cmds.file(removeReference=True, referenceNode=myRefNode)

Here’s the weird thing: If I comment out that line, the script runs quickly. If I then run just that line through the Script Editor, it removes the reference quickly. No stalling.

I’ve been trying a few different things to avoid the stall, but no luck so far. Does anyone have any ideas? Has anyone seen anything like this before?

Did you ever get any resolution to this? I think I’m seeing something similar – a really extreme delay in opening a file with references in batch or creating a new file after modifying a file with references in it.
I’m wondering if it has to do with the reference edits themselves.