Commit 3392368
authored
⚡️ Speed up function
The optimized code achieves a **29% speedup** through two key optimizations that reduce overhead in the inner loop:
**Key optimizations:**
1. **Eliminates repeated attribute lookups**: Caches `parsed_selector.definition.property_name` in a local variable instead of accessing it twice per inner loop iteration
2. **Reduces dictionary access overhead**: Stores a reference to the target set (`batch_compatibility_of_properties[property_name]`) and reuses it, avoiding repeated dictionary lookups
3. **Uses in-place set union (`|=`)** instead of the `update()` method, which has slightly less overhead for set operations
**Performance impact by test case:**
- **Small inputs (1-10 selectors)**: Modest 1-10% improvements due to reduced method call overhead
- **Medium inputs (100-500 selectors)**: 12-25% speedups as the optimizations compound with more iterations
- **Large inputs with many references**: Up to 149% improvement in cases with many references per selector, where the inner loop dominates runtime
The line profiler shows the optimization moves expensive work (attribute lookups and dictionary access) from the inner loop to the outer loop. The original code performed `parsed_selector.definition.property_name` lookup 12,672 times, while the optimized version does it only 3,432 times - exactly once per selector instead of once per reference.
This optimization is particularly effective for workflows with selectors containing many allowed references, which is common in batch processing scenarios.retrieve_batch_compatibility_of_input_selectors by 30% in PR #1504 (feature/try-to-beat-the-limitation-of-ee-in-terms-of-singular-elements-pushed-into-batch-inputs)1 parent ac237f2 commit 3392368
File tree
1 file changed
+15
-3
lines changed- inference/core/workflows/execution_engine/v1/compiler
1 file changed
+15
-3
lines changedLines changed: 15 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
| 738 | + | |
738 | 739 | | |
739 | 740 | | |
740 | 741 | | |
741 | 742 | | |
| 743 | + | |
742 | 744 | | |
743 | 745 | | |
744 | 746 | | |
745 | 747 | | |
746 | 748 | | |
747 | 749 | | |
748 | 750 | | |
| 751 | + | |
749 | 752 | | |
750 | 753 | | |
751 | 754 | | |
752 | 755 | | |
753 | 756 | | |
754 | 757 | | |
| 758 | + | |
755 | 759 | | |
| 760 | + | |
756 | 761 | | |
| 762 | + | |
757 | 763 | | |
758 | 764 | | |
759 | 765 | | |
| |||
812 | 818 | | |
813 | 819 | | |
814 | 820 | | |
| 821 | + | |
| 822 | + | |
815 | 823 | | |
816 | 824 | | |
817 | 825 | | |
| |||
1563 | 1571 | | |
1564 | 1572 | | |
1565 | 1573 | | |
| 1574 | + | |
| 1575 | + | |
1566 | 1576 | | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
| 1577 | + | |
1570 | 1578 | | |
1571 | 1579 | | |
1572 | 1580 | | |
| |||
1606 | 1614 | | |
1607 | 1615 | | |
1608 | 1616 | | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
1609 | 1620 | | |
1610 | 1621 | | |
1611 | 1622 | | |
| |||
1654 | 1665 | | |
1655 | 1666 | | |
1656 | 1667 | | |
| 1668 | + | |
1657 | 1669 | | |
1658 | 1670 | | |
1659 | 1671 | | |
| |||
0 commit comments