I noticed some really bad performance, and my profiler pointed me to this construct:
right_mapping = next((
mapping
for mapping in ref_dat_mapping.map
if all(
legacy_object[k] == mapping[k]
for k in ref_dat_mapping.mapped_legacy_keys
)
), None)
I replaced it with the following, with instant improvements:
right_mapping = None
for mapping in ref_dat_mapping.map:
if all(
legacy_object[k] == mapping[k]
for k in ref_dat_mapping.mapped_legacy_keys
):
right_mapping = mapping
break
Why is the latter construct twice as fast? Are there even faster ways of achieving this?