Can you use a more performant undo function than RegisterSceneUndo with DestroyImmediate?

The documentation states that Undo.RegisterSceneUndo is the slowest way to undo an operation, and that makes sense. However, it doesn't suggest an alternative, when the operation involves a DestroyImmediate(); call. I couldn't get a regular RegisterUndo to work, because the objects that I put into the objectsToUndo array were no longer available after the operation ended.

Currently the only way to register an undo function that revert object deletion is through RegisterSceneUndo.

Internally we usually use this function only if it is not possible to implement it in another way, for example in this very case.

What kinds of Objects were you putting into RegisterUndo? Because looking at the description, it says,

"Note that only the actual objects passed as parameters are saved. For example, passing a game object will not save all its components or child objects. If you need to save the state of an entire game object, you can use EditorUtility.CollectDeepHierarchy on the game object to get all the objects that it contains and pass all those objects as objects to undo."

I haven't looked at Undo before, but it could be that your top-level Object isn't available because all of its components are gone (making it no longer functional). You may need to save everything, as noted above.