Commit e2949d1
authored
⚡️ Speed up function
The optimized code replaces a manual linear search with Python's built-in `max()` function, delivering a **26% speedup** by eliminating redundant operations.
**Key optimizations:**
1. **Single-pass iteration**: The original code performs 12,601 iterations with 12,550 length comparisons. The optimized version uses `max(all_lineages_of_batch_parameters, key=len, default=[])` which iterates once and delegates the comparison logic to highly optimized C code.
2. **Eliminates repeated `len()` calls**: The original code calls `len(longest_longest_lineage_support)` on every comparison (12,550 times), recalculating the same length repeatedly. The optimized version calculates each lineage's length exactly once.
3. **Removes variable assignments**: The original code performs 3,104 assignment operations when updating the longest lineage. The optimized version eliminates these assignments entirely.
**Performance characteristics by test case:**
- **Small inputs (< 10 lineages)**: The optimization shows 50-60% slower performance due to function call overhead, but these cases run in microseconds where the difference is negligible.
- **Large inputs (1000+ lineages)**: Shows 30-55% speedup, where the optimization truly shines. For example, `test_large_with_varying_lengths` improves from 62.1μs to 40.4μs (54% faster).
- **Best case scenarios**: When the longest lineage appears early or when many lineages share the maximum length, the original code still must scan the entire list, while `max()` maintains consistent performance.
The optimization is most effective for workflows processing large batches of lineage data, which appears to be the primary use case based on the test suite.find_longest_lineage_support by 26% in PR #1504 (feature/try-to-beat-the-limitation-of-ee-in-terms-of-singular-elements-pushed-into-batch-inputs)1 parent 9e7765a commit e2949d1
File tree
1 file changed
+3
-6
lines changed- inference/core/workflows/execution_engine/v1/compiler
1 file changed
+3
-6
lines changedLines changed: 3 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1672 | 1672 | | |
1673 | 1673 | | |
1674 | 1674 | | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
1679 | | - | |
| 1675 | + | |
| 1676 | + | |
1680 | 1677 | | |
1681 | | - | |
| 1678 | + | |
1682 | 1679 | | |
1683 | 1680 | | |
1684 | 1681 | | |
| |||
0 commit comments