Here is an optimized version of your program. ### Major inefficiency The code computed `EntityNode.model_fields.keys()` **every call** to the function, but that is invariant and need only be computed once per module. Likewise, it looked up `.keys()` for every entity type model, though these could be checked far more efficiently via set intersection. ### Key performance improvements. - `EntityNode.model_fields.keys()` evaluated **once**, as a set, and reused. - Comparison per entity type uses `set` intersection (O(min(N, M))) instead of repeated linear search. - Only a single scan over each entity type model's fields, not recomputed unnecessarily. The function signature and error handling are unchanged, and all preserved comments are respected. This implementation will be significantly faster for many input types. |
||
|---|---|---|
| .. | ||
| maintenance | ||
| ontology_utils | ||
| __init__.py | ||
| bulk_utils.py | ||
| datetime_utils.py | ||