Commit f69e354
enhance: general performance improvements across MilvusClient path (#3279)
## Summary
- **Fix duplicate `@retry_on_rpc_failure`** on `search()` in
`grpc_handler.py` — was causing up to 75×75=5625 retry attempts instead
of 75
- **24 micro-optimizations** across the MilvusClient/AsyncMilvusClient
code path (no refactoring, no API changes):
- Replace O(n²) bytes concatenation with `b"".join` and `struct.pack`
batch (~136x faster at n=1000)
- Use `orjson.loads` instead of stdlib `json.loads` (~6.7x faster)
- Replace `deepcopy` with shallow `dict()` for search params (~4.2x
faster)
- Use `frozenset` for O(1) membership checks instead of list O(n) (~3.6x
faster)
- Use `WhichOneof` instead of cascading `HasField` in `len_of`
- Use `time.monotonic` + lazy `traceback.format_exc` in error_handler
(~13-17x faster)
- Use builtin `isinstance(x, dict/list)` instead of `typing.Dict/List`
(~3.3-6.5x faster)
- Cache protobuf attribute chains to avoid repeated traversals (~1.3x
faster)
- Use dict dispatch tables instead of if/elif chains
- Move per-call dict/function creation to module-level constants (~4.5x
faster)
- Use `template.copy()` instead of `dict.fromkeys` per iteration (~5.4x
faster)
- Skip dynamic field json comprehension when dynamic is disabled (~16x
faster)
- Consolidate `extend([item])` to `append` (~2.8x faster)
- **80 benchmark tests** added in
`tests/benchmark/test_perf_improvements.py` covering all optimization
patterns
- Net **-536 / +1562 lines** across 11 files (10 production + 1
benchmark test file)
- All 2126 existing unit tests pass, all 80 benchmark tests pass
## Test plan
- [x] `make lint` passes (black + ruff clean)
- [x] `make unittest` — 2126 passed, 4 skipped, 1 xfailed
- [x] `pytest tests/benchmark/test_perf_improvements.py` — 80 benchmarks
pass
- [ ] CI checks pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 921e74b commit f69e354
File tree
11 files changed
+1562
-536
lines changed- pymilvus
- client
- milvus_client
- tests/benchmark
11 files changed
+1562
-536
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
1414 | 1414 | | |
1415 | 1415 | | |
1416 | 1416 | | |
1417 | | - | |
| 1417 | + | |
| 1418 | + | |
1418 | 1419 | | |
1419 | 1420 | | |
1420 | 1421 | | |
| |||
1620 | 1621 | | |
1621 | 1622 | | |
1622 | 1623 | | |
1623 | | - | |
| 1624 | + | |
1624 | 1625 | | |
1625 | 1626 | | |
1626 | 1627 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | | - | |
1225 | 1224 | | |
1226 | 1225 | | |
1227 | 1226 | | |
| |||
1590 | 1589 | | |
1591 | 1590 | | |
1592 | 1591 | | |
1593 | | - | |
| 1592 | + | |
1594 | 1593 | | |
1595 | 1594 | | |
1596 | 1595 | | |
| |||
2201 | 2200 | | |
2202 | 2201 | | |
2203 | 2202 | | |
2204 | | - | |
| 2203 | + | |
| 2204 | + | |
2205 | 2205 | | |
2206 | 2206 | | |
2207 | 2207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
60 | 70 | | |
61 | 71 | | |
62 | 72 | | |
| |||
558 | 568 | | |
559 | 569 | | |
560 | 570 | | |
561 | | - | |
| 571 | + | |
562 | 572 | | |
563 | 573 | | |
564 | 574 | | |
| |||
784 | 794 | | |
785 | 795 | | |
786 | 796 | | |
787 | | - | |
| 797 | + | |
788 | 798 | | |
789 | 799 | | |
790 | 800 | | |
| |||
838 | 848 | | |
839 | 849 | | |
840 | 850 | | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | 851 | | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
848 | 857 | | |
849 | 858 | | |
850 | 859 | | |
| |||
939 | 948 | | |
940 | 949 | | |
941 | 950 | | |
942 | | - | |
| 951 | + | |
943 | 952 | | |
944 | 953 | | |
945 | 954 | | |
| |||
999 | 1008 | | |
1000 | 1009 | | |
1001 | 1010 | | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
1009 | 1017 | | |
1010 | 1018 | | |
1011 | 1019 | | |
| |||
1049 | 1057 | | |
1050 | 1058 | | |
1051 | 1059 | | |
1052 | | - | |
| 1060 | + | |
1053 | 1061 | | |
1054 | 1062 | | |
1055 | 1063 | | |
| |||
1551 | 1559 | | |
1552 | 1560 | | |
1553 | 1561 | | |
1554 | | - | |
1555 | | - | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
1562 | | - | |
1563 | | - | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
| 1562 | + | |
| 1563 | + | |
1567 | 1564 | | |
| 1565 | + | |
1568 | 1566 | | |
1569 | 1567 | | |
1570 | 1568 | | |
| |||
1708 | 1706 | | |
1709 | 1707 | | |
1710 | 1708 | | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
1741 | 1713 | | |
1742 | | - | |
| 1714 | + | |
| 1715 | + | |
1743 | 1716 | | |
1744 | | - | |
1745 | | - | |
| 1717 | + | |
1746 | 1718 | | |
1747 | 1719 | | |
1748 | 1720 | | |
| |||
0 commit comments