Skip to content

refactor: clean up include dependencies in src/ based on IWYU analysis#2145

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:opencode/iwyu-cleanup-src-includes
Open

refactor: clean up include dependencies in src/ based on IWYU analysis#2145
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:opencode/iwyu-cleanup-src-includes

Conversation

@LHT129
Copy link
Copy Markdown
Collaborator

@LHT129 LHT129 commented Jun 4, 2026

Closes #2144

What

Clean up include dependencies across 148 implementation files (.cpp) in src/ based on IWYU (include-what-you-use) analysis.

Why

IWYU analysis identified the following issues in src/:

  1. Redundant heavy headers: 56 files use <fmt/format.h> but only need <fmt/core.h>
  2. Over-reliance on aggregate headers: common.h, filter_headers.h, io_headers.h, quantizer_headers.h, etc. pull in far more dependencies than needed
  3. Missing explicit includes: Some symbols are only available via transitive dependencies without direct includes

Changes

Commit 1: Replace fmt headers (56 files)

  • <fmt/format.h><fmt/core.h>
  • No behavioral change; fmt/core.h is a strict subset of fmt/format.h

Commit 2: IWYU include cleanup (148 files)

  • Split aggregate headers into specific headers actually needed
  • Add missing explicit includes for symbols used
  • Remove unused includes
  • +1,424 lines, -117 lines

Verification

  • make release build passes
  • make fmt format check passes

Affected Directories

algorithm/, analyzer/, attr/, datacell/, factory/, impl/, index/, io/, quantization/, simd/, storage/, utils/, src/ root

Copilot AI review requested due to automatic review settings June 4, 2026 09:28
@LHT129 LHT129 self-assigned this Jun 4, 2026
@LHT129 LHT129 added kind/improvement Code improvements (variable/function renaming, refactoring, etc. ) version/1.0 labels Jun 4, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Jun 4, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Require kind label

Wonderful, this rule succeeded.
  • label~=^kind/

🟢 Require version label

Wonderful, this rule succeeded.
  • label~=^version/

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the inclusion of <fmt/format.h> with <fmt/core.h> across numerous source and header files to optimize compilation times and minimize dependencies. As there are no review comments, I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates src/ to prefer the lighter-weight {fmt} header by replacing #include <fmt/format.h> with #include <fmt/core.h> (per IWYU findings), reducing preprocessing overhead without changing runtime behavior.

Changes:

  • Replaced {fmt} includes across 56 src/ files: <fmt/format.h><fmt/core.h>.
  • No functional logic changes; includes-only refactor intended to improve compile times.

Reviewed changes

Copilot reviewed 56 out of 56 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/storage/stream_reader.cpp Switch {fmt} include to <fmt/core.h>.
src/storage/footer.h Switch {fmt} include to <fmt/core.h>.
src/reader.cpp Switch {fmt} include to <fmt/core.h>.
src/quantization/transform_quantization/transform_quantizer_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/quantization/rabitq_quantization/rabitq_quantizer_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/quantization/quantizer_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/options.cpp Switch {fmt} include to <fmt/core.h>.
src/io/reader_io.cpp Switch {fmt} include to <fmt/core.h>.
src/io/mmap_io_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/io/buffer_io_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/io/basic_io.h Switch {fmt} include to <fmt/core.h>.
src/io/async_io_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/index/hnsw.cpp Switch {fmt} include to <fmt/core.h>.
src/index/hnsw_zparameters.cpp Switch {fmt} include to <fmt/core.h>.
src/index/diskann_zparameters.cpp Switch {fmt} include to <fmt/core.h>.
src/index_feature_list.cpp Switch {fmt} include to <fmt/core.h>.
src/index_common_param.cpp Switch {fmt} include to <fmt/core.h>.
src/impl/transform/vector_transformer_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/impl/transform/random_orthogonal_transformer.cpp Switch {fmt} include to <fmt/core.h>.
src/impl/transform/pca_transformer.cpp Switch {fmt} include to <fmt/core.h>.
src/impl/odescent/odescent_graph_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/impl/logger/logger.h Switch {fmt} include to <fmt/core.h>.
src/impl/label_table/label_table.h Switch {fmt} include to <fmt/core.h>.
src/impl/allocator/default_allocator.cpp Switch {fmt} include to <fmt/core.h>.
src/factory/index_creators.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/sparse_vector_datacell_parameter.h Switch {fmt} include to <fmt/core.h>.
src/datacell/sparse_graph_datacell_test.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/multi_vector_datacell_test.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/multi_vector_datacell_parameter.h Switch {fmt} include to <fmt/core.h>.
src/datacell/graph_datacell_test.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/graph_datacell_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/flatten_datacell_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/extra_info_interface.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/extra_info_datacell_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/compressed_graph_datacell_test.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/bucket_interface.cpp Switch {fmt} include to <fmt/core.h>.
src/datacell/bucket_datacell_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/attr/expression_visitor.h Switch {fmt} include to <fmt/core.h>.
src/algorithm/warp/warp_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/sindi/term_id_mapper.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/ivf_partition_strategy_parameter.h Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/ivf_partition_strategy_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/ivf_parameter.h Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/ivf_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/ivf_nearest_partition.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/gno_imi_partition.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/gno_imi_parameter.h Switch {fmt} include to <fmt/core.h>.
src/algorithm/ivf/gno_imi_parameter.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/inner_index_interface.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph_serialize.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph_search.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph_parameter_test.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph_param_mapping.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/hgraph/hgraph_build.cpp Switch {fmt} include to <fmt/core.h>.
src/algorithm/bruteforce/bruteforce_parameter.cpp Switch {fmt} include to <fmt/core.h>.

Comment thread src/io/reader_io.cpp Outdated
Comment on lines 15 to 19
#include "reader_io.h"

#include <fmt/format.h>
#include <fmt/core.h>

#include <future>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file no longer includes fmt/core.h in the latest push — the unused include was already removed.

@mergify mergify Bot added the module/simd label Jun 4, 2026
@LHT129 LHT129 changed the title refactor: replace fmt/format.h with fmt/core.h in src/ refactor: 基于IWYU分析清理src/实现文件的include依赖 Jun 4, 2026
@LHT129 LHT129 changed the title refactor: 基于IWYU分析清理src/实现文件的include依赖 refactor: clean up include dependencies in src/ based on IWYU analysis Jun 4, 2026
@LHT129 LHT129 force-pushed the opencode/iwyu-cleanup-src-includes branch from 787bbae to 6ff0a2b Compare June 4, 2026 11:22
Copilot AI review requested due to automatic review settings June 4, 2026 11:31
@LHT129 LHT129 force-pushed the opencode/iwyu-cleanup-src-includes branch from 6ff0a2b to 296f33d Compare June 4, 2026 11:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 173 out of 173 changed files in this pull request and generated 9 comments.

Comment thread src/impl/logger/default_logger.cpp Outdated
Comment on lines 18 to 22
#include <bits/types/struct_tm.h>
#include <cxxabi.h>
#include <unistd.h>

#include <chrono>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed <bits/types/struct_tm.h> (redundant with ), removed unused <cxxabi.h>, added for std::ostringstream.

Comment thread src/utils/sparse_vector_transform.cpp Outdated
Comment on lines +19 to +23
#include <bits/std_abs.h>

#include <algorithm>
#include <cstdint>
#include <unordered_map>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: replaced <bits/std_abs.h> with across all affected files.

Comment thread src/utils/lock_strategy.cpp Outdated

#include "lock_strategy.h"

#include <ext/alloc_traits.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed <ext/alloc_traits.h> from all files — it is unused and libstdc++-specific.

Comment thread src/algorithm/hgraph/hgraph.cpp Outdated

#include <datacell/compressed_graph_datacell_parameter.h>
#include <fmt/format.h>
#include <bits/std_abs.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed <bits/std_abs.h>, ensured is present instead.

Comment thread src/algorithm/hgraph/hgraph.cpp Outdated
#include <atomic>
#include <cmath>
#include <cstdint>
#include <ext/alloc_traits.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed <ext/alloc_traits.h>.

Comment thread src/impl/blas/blas_function.cpp Outdated
Comment on lines 17 to 20
#include <cblas.h>
#include <lapack.h>
#include <lapacke.h>
#include <omp.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: restored blas_compat.h and removed direct <cblas.h>/<lapack.h>/<lapacke.h> includes.

Comment thread src/utils/timer.cpp Outdated
#include "timer.h"

#include <numeric>
#include <ratio>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: replaced with for std::numeric_limits usage.

#include "default_thread_pool.h"

#include "vsag/options.h"
#include <cxxabi.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed unused <cxxabi.h>.

Comment thread src/impl/searcher/basic_searcher.cpp Outdated
#include <chrono>
#include <cstring>
#include <cstdint>
#include <ext/alloc_traits.h>
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: removed <ext/alloc_traits.h>.

@LHT129 LHT129 force-pushed the opencode/iwyu-cleanup-src-includes branch from 296f33d to c28363a Compare June 5, 2026 05:23
- Replace fmt/format.h with fmt/core.h (56 files)
- Split aggregate headers (common.h, filter_headers.h, etc.) into specific headers
- Add missing explicit includes for symbols used
- Remove unused includes
- 148 files changed, +1424 -117 lines

Signed-off-by: LHT129 <tianlan.lht@antgroup.com>
@LHT129 LHT129 force-pushed the opencode/iwyu-cleanup-src-includes branch from c28363a to ebba4f6 Compare June 5, 2026 07:04
Copilot AI review requested due to automatic review settings June 5, 2026 07:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 172 out of 172 changed files in this pull request and generated 4 comments.

Comment on lines 21 to +23
#include <cstdint>
#include <fstream>
#include <iostream>
#include <limits>
#include <utility>
Comment thread src/json_wrapper.cpp
Comment on lines +19 to +24
#include <initializer_list>
#include <map>
#include <nlohmann/json.hpp>

#include "nlohmann/detail/json_pointer.hpp"
#include "nlohmann/json_fwd.hpp"
Comment thread src/io/io_parameter.cpp
Comment on lines 23 to 25
#include "async_io_parameter.h"
#include "buffer_io_parameter.h"
#include "impl/logger/logger.h"
#include "inner_string_params.h"
#include "default_thread_pool.h"

#include "vsag/options.h"
#include "ThreadPool.h"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up include dependencies in src/ implementation files based on IWYU analysis

2 participants