Commit 08e06e6
perf(search): cache metric instruments in hot vector-sync path
Codex review on PR #754 flagged that _log_vector_sync_complete runs
per entity in large sync batches, and each call now goes through
logfire.metric_histogram(...).record(...) — OTel's MeterProvider
lookup is O(1) but still non-free under load. The original
telemetry wrapper cached instruments in a process-wide dict; my
strip lost that.
Restores the cache as two small module-level helpers in
search_repository_base.py (_metric_histogram / _metric_counter)
so instruments are resolved once and reused. Callers switch to
the helpers (11 sites).
Tests clear _METRIC_INSTRUMENTS via monkeypatch so fake factories
win on the first lookup.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>1 parent 7ce47d7 commit 08e06e6
2 files changed
Lines changed: 36 additions & 11 deletions
File tree
- src/basic_memory/repository
- tests/repository
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
44 | 67 | | |
45 | 68 | | |
46 | 69 | | |
| |||
1069 | 1092 | | |
1070 | 1093 | | |
1071 | 1094 | | |
1072 | | - | |
| 1095 | + | |
1073 | 1096 | | |
1074 | 1097 | | |
1075 | 1098 | | |
| |||
1079 | 1102 | | |
1080 | 1103 | | |
1081 | 1104 | | |
1082 | | - | |
| 1105 | + | |
1083 | 1106 | | |
1084 | 1107 | | |
1085 | 1108 | | |
1086 | 1109 | | |
1087 | 1110 | | |
1088 | 1111 | | |
1089 | | - | |
| 1112 | + | |
1090 | 1113 | | |
1091 | 1114 | | |
1092 | 1115 | | |
1093 | 1116 | | |
1094 | 1117 | | |
1095 | 1118 | | |
1096 | | - | |
| 1119 | + | |
1097 | 1120 | | |
1098 | 1121 | | |
1099 | 1122 | | |
1100 | 1123 | | |
1101 | 1124 | | |
1102 | 1125 | | |
1103 | | - | |
| 1126 | + | |
1104 | 1127 | | |
1105 | 1128 | | |
1106 | 1129 | | |
1107 | 1130 | | |
1108 | 1131 | | |
1109 | 1132 | | |
1110 | | - | |
| 1133 | + | |
1111 | 1134 | | |
1112 | 1135 | | |
1113 | 1136 | | |
1114 | 1137 | | |
1115 | 1138 | | |
1116 | 1139 | | |
1117 | | - | |
| 1140 | + | |
1118 | 1141 | | |
1119 | 1142 | | |
1120 | 1143 | | |
| |||
1694 | 1717 | | |
1695 | 1718 | | |
1696 | 1719 | | |
1697 | | - | |
| 1720 | + | |
1698 | 1721 | | |
1699 | 1722 | | |
1700 | 1723 | | |
| |||
1704 | 1727 | | |
1705 | 1728 | | |
1706 | 1729 | | |
1707 | | - | |
| 1730 | + | |
1708 | 1731 | | |
1709 | 1732 | | |
1710 | 1733 | | |
| |||
1714 | 1737 | | |
1715 | 1738 | | |
1716 | 1739 | | |
1717 | | - | |
| 1740 | + | |
1718 | 1741 | | |
1719 | 1742 | | |
1720 | 1743 | | |
| |||
1724 | 1747 | | |
1725 | 1748 | | |
1726 | 1749 | | |
1727 | | - | |
| 1750 | + | |
1728 | 1751 | | |
1729 | 1752 | | |
1730 | 1753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
712 | 712 | | |
713 | 713 | | |
714 | 714 | | |
| 715 | + | |
| 716 | + | |
715 | 717 | | |
716 | 718 | | |
717 | 719 | | |
| |||
0 commit comments