Commit b6f8936
authored
perf(index): avoid HEAD call when opening vector indexes (#7064)
Closes #6944
## Problem
Opening a vector index made an extra network request to find out how big
the index file was. We do not need that request. The file size is
already saved in the manifest, in `IndexMetadata.files`.
`Dataset::open_vector_index` opens `index.idx` just to read the footer
and work out the format version. The plain `open` call does not know the
file size, so the reader sends a HEAD request to get it. This happens
for every vector index, not only HNSW. On the modern reader path the
file is then opened a second time with the size already known, so the
first HEAD was wasted. The same wasted HEAD also happened on the HNSW
auxiliary file open (the case named in the issue), on the legacy remap
path, and on legacy detail inference.
## Changes
Added one small helper, `open_index_file`. It reads the size from the
manifest (`IndexMetadata::file_size_map()`) and opens the file with
`open_with_size`. If the size is not recorded, which is the case for
older indices, it falls back to the plain `open`.
The helper is now used everywhere a vector index file is opened:
- `index.rs`, the main open that detects the format version (IVF_PQ,
IVF_RQ, FLAT). This also removes a duplicate `file_size_map()` call in
the same path.
- `vector.rs`, the `IVF_HNSW_PQ` and `IVF_HNSW_SQ` auxiliary file opens.
- `ivf.rs`, the legacy v1 `remap_index_file`.
- `details.rs`, the legacy `infer_vector_index_details` fallback.
## Testing
- New test `test_open_index_file_skips_head_when_size_known`. It wraps
the store in a proxy that counts metadata reads against the index file.
The result is 0 HEAD requests when the size is known and 1 HEAD on the
older fallback path.
- `cargo fmt --all`
- `cargo clippy -p lance --tests -- -D warnings`, clean.
- `cargo test -p lance --lib index::vector::`, 208 passed.1 parent 466405f commit b6f8936
4 files changed
Lines changed: 182 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1877 | 1877 | | |
1878 | 1878 | | |
1879 | 1879 | | |
1880 | | - | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
1881 | 1889 | | |
1882 | 1890 | | |
1883 | 1891 | | |
| |||
1944 | 1952 | | |
1945 | 1953 | | |
1946 | 1954 | | |
1947 | | - | |
1948 | 1955 | | |
1949 | 1956 | | |
1950 | 1957 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
1588 | 1589 | | |
1589 | 1590 | | |
1590 | 1591 | | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
1591 | 1610 | | |
1592 | 1611 | | |
1593 | 1612 | | |
| |||
1612 | 1631 | | |
1613 | 1632 | | |
1614 | 1633 | | |
| 1634 | + | |
1615 | 1635 | | |
1616 | 1636 | | |
1617 | 1637 | | |
1618 | 1638 | | |
1619 | | - | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
1620 | 1646 | | |
1621 | 1647 | | |
1622 | 1648 | | |
| |||
1643 | 1669 | | |
1644 | 1670 | | |
1645 | 1671 | | |
1646 | | - | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
1647 | 1679 | | |
1648 | 1680 | | |
1649 | 1681 | | |
| |||
1960 | 1992 | | |
1961 | 1993 | | |
1962 | 1994 | | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
| 2035 | + | |
| 2036 | + | |
| 2037 | + | |
| 2038 | + | |
| 2039 | + | |
| 2040 | + | |
| 2041 | + | |
| 2042 | + | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
| 2051 | + | |
| 2052 | + | |
| 2053 | + | |
| 2054 | + | |
| 2055 | + | |
| 2056 | + | |
| 2057 | + | |
| 2058 | + | |
| 2059 | + | |
| 2060 | + | |
| 2061 | + | |
| 2062 | + | |
| 2063 | + | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
1963 | 2114 | | |
1964 | 2115 | | |
1965 | 2116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
506 | | - | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
507 | 515 | | |
508 | 516 | | |
509 | 517 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
1842 | 1844 | | |
1843 | 1845 | | |
1844 | 1846 | | |
1845 | | - | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
1846 | 1856 | | |
1847 | 1857 | | |
1848 | 1858 | | |
| |||
0 commit comments