It looks like invoking deepcopy on all fields for constraints and tables takes a significant amount of time, since we end up copying nested objects that we don't care about in the final result.
Instead, we can copy only the dictionaries that we're going to modify, and then deepcopy the final result (which is going to be much smaller).
The difference is drastic: on my database (250+ tables), this speeds up dbtoyaml from 70 seconds to 1.2 seconds, with the same final YAML generated.
It looks like invoking deepcopy on all fields for constraints and tables takes a significant amount of time, since we end up copying nested objects that we don't care about in the final result.
Instead, we can copy only the dictionaries that we're going to modify, and then deepcopy the final result (which is going to be much smaller).
The difference is drastic: on my database (250+ tables), this speeds up dbtoyaml from 70 seconds to 1.2 seconds, with the same final YAML generated.