I
Inquisitive Scientist
I am having problems with running copy.deepcopy on very large data
structures containing lots of numeric data:
1. copy.deepcopy can be very slow
2. copy.deepcopy can cause memory errors even when I have plenty of
memory
I think the problem is that the current implementation keeps a memo
for everything it copies even immutable types. In addition to being
slow, this makes the memo dict grow very large when there is lots of
simple numeric data to be copied. For long running programs, large
memo dicts seem to cause memory fragmentation and result in memory
errors.
It seems like this could be easily fixed by adding the following lines
at the very start of the deepcopy function:
if isinstance(x, (type(None), int, long, float, bool, str)):
return x
This seems perfectly safe, should speed things up, keep the memo dict
smaller, and be easy to add. Can someone add this to copy.py or point
me to the proper procedure for requesting this change in copy.py?
Thanks,
-I.S.
structures containing lots of numeric data:
1. copy.deepcopy can be very slow
2. copy.deepcopy can cause memory errors even when I have plenty of
memory
I think the problem is that the current implementation keeps a memo
for everything it copies even immutable types. In addition to being
slow, this makes the memo dict grow very large when there is lots of
simple numeric data to be copied. For long running programs, large
memo dicts seem to cause memory fragmentation and result in memory
errors.
It seems like this could be easily fixed by adding the following lines
at the very start of the deepcopy function:
if isinstance(x, (type(None), int, long, float, bool, str)):
return x
This seems perfectly safe, should speed things up, keep the memo dict
smaller, and be easy to add. Can someone add this to copy.py or point
me to the proper procedure for requesting this change in copy.py?
Thanks,
-I.S.