Commit 74fce30
enhance: general performance improvements across MilvusClient path (#3280)
- **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
- [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
(cherry picked from commit f69e354)
---------
Signed-off-by: yangxuan <xuan.yang@zilliz.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 91e5222 commit 74fce30
File tree
11 files changed
+1557
-522
lines changed- pymilvus
- client
- milvus_client
- tests/benchmark
11 files changed
+1557
-522
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 | | |
| |||
1410 | 1410 | | |
1411 | 1411 | | |
1412 | 1412 | | |
1413 | | - | |
| 1413 | + | |
| 1414 | + | |
1414 | 1415 | | |
1415 | 1416 | | |
1416 | 1417 | | |
| |||
1616 | 1617 | | |
1617 | 1618 | | |
1618 | 1619 | | |
1619 | | - | |
| 1620 | + | |
1620 | 1621 | | |
1621 | 1622 | | |
1622 | 1623 | | |
| |||
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 | | |
| |||
1162 | 1162 | | |
1163 | 1163 | | |
1164 | 1164 | | |
1165 | | - | |
1166 | 1165 | | |
1167 | 1166 | | |
1168 | 1167 | | |
| |||
1531 | 1530 | | |
1532 | 1531 | | |
1533 | 1532 | | |
1534 | | - | |
| 1533 | + | |
1535 | 1534 | | |
1536 | 1535 | | |
1537 | 1536 | | |
| |||
2142 | 2141 | | |
2143 | 2142 | | |
2144 | 2143 | | |
2145 | | - | |
| 2144 | + | |
| 2145 | + | |
2146 | 2146 | | |
2147 | 2147 | | |
2148 | 2148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
| |||
557 | 567 | | |
558 | 568 | | |
559 | 569 | | |
560 | | - | |
| 570 | + | |
561 | 571 | | |
562 | 572 | | |
563 | 573 | | |
| |||
783 | 793 | | |
784 | 794 | | |
785 | 795 | | |
786 | | - | |
| 796 | + | |
787 | 797 | | |
788 | 798 | | |
789 | 799 | | |
| |||
837 | 847 | | |
838 | 848 | | |
839 | 849 | | |
840 | | - | |
841 | | - | |
842 | | - | |
843 | | - | |
844 | | - | |
845 | | - | |
846 | 850 | | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
847 | 856 | | |
848 | 857 | | |
849 | 858 | | |
| |||
938 | 947 | | |
939 | 948 | | |
940 | 949 | | |
941 | | - | |
| 950 | + | |
942 | 951 | | |
943 | 952 | | |
944 | 953 | | |
| |||
998 | 1007 | | |
999 | 1008 | | |
1000 | 1009 | | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | 1010 | | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
1008 | 1016 | | |
1009 | 1017 | | |
1010 | 1018 | | |
| |||
1048 | 1056 | | |
1049 | 1057 | | |
1050 | 1058 | | |
1051 | | - | |
| 1059 | + | |
1052 | 1060 | | |
1053 | 1061 | | |
1054 | 1062 | | |
| |||
1546 | 1554 | | |
1547 | 1555 | | |
1548 | 1556 | | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
1556 | | - | |
1557 | | - | |
1558 | | - | |
1559 | | - | |
1560 | | - | |
1561 | | - | |
| 1557 | + | |
| 1558 | + | |
1562 | 1559 | | |
| 1560 | + | |
1563 | 1561 | | |
1564 | 1562 | | |
1565 | 1563 | | |
| |||
1699 | 1697 | | |
1700 | 1698 | | |
1701 | 1699 | | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
1708 | | - | |
1709 | | - | |
1710 | | - | |
1711 | | - | |
1712 | | - | |
1713 | | - | |
1714 | | - | |
1715 | | - | |
1716 | | - | |
1717 | | - | |
1718 | | - | |
1719 | | - | |
1720 | | - | |
1721 | | - | |
1722 | | - | |
1723 | | - | |
1724 | | - | |
1725 | | - | |
1726 | | - | |
1727 | | - | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
1732 | 1704 | | |
1733 | | - | |
| 1705 | + | |
| 1706 | + | |
1734 | 1707 | | |
1735 | | - | |
1736 | | - | |
| 1708 | + | |
1737 | 1709 | | |
1738 | 1710 | | |
1739 | 1711 | | |
| |||
0 commit comments