robshakir / pyangbind

A plugin for pyang that creates Python bindings for a YANG model.
Other
198 stars 120 forks source link

Optimisation: change class_map deepcopy to copy #316

Closed fperrin closed 9 months ago

fperrin commented 10 months ago

This is an improvement by a colleague of mine, @jamie01

pyangbind was taking around 18 seconds on my machine to create the classes for the collection of YANG models for a proprietary routing device. After doing some profiling, deepcopy operations were by far the worst offenders and in particular the deepcopy of "class_map" - a large structure containing all the yang types seen along the way.

Since the copied var doesn't modify deeply nested data, swapping it for a copy seemed reasonable. If I diff the python output file from deepcopy vs copy the files are identical. And not only that, the whole process now completes in under 4 seconds.