Repository navigation
fix(pyOpenMS): patch nanobind __forceinline on MSVC to fix compile-time blowup - #8933
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughA MSVC-only patch was added to Changes
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/pyOpenMS/CMakeLists.txt (1)
154-165: Narrow the patch guard to FetchContent-only to avoid accidental writes to pre-installed nanobind.Using
nanobind_SOURCE_DIRalone is insufficient because this variable may be defined regardless of whether nanobind was fetched or found viafind_package. When nanobind is installed (find_package path), the patch should not run, as it targets a development/build-time compilation fix specific to locally-fetched copies. Guard withnanobind_POPULATEDto ensure the in-placefile(WRITE ...)only runs afterFetchContent_MakeAvailable(nanobind).♻️ Proposed guard refinement
- if(MSVC AND nanobind_SOURCE_DIR) + if(MSVC AND nanobind_POPULATED AND nanobind_SOURCE_DIR)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/pyOpenMS/CMakeLists.txt` around lines 154 - 165, The current patch uses nanobind_SOURCE_DIR to decide whether to modify nb_defs.h, which can be set even for an installed nanobind; change the guard to ensure this only runs for FetchContent-provided nanobind by testing nanobind_POPULATED (set by FetchContent_MakeAvailable) instead of or in addition to nanobind_SOURCE_DIR; i.e., wrap the existing logic that reads/writes "${nanobind_SOURCE_DIR}/include/nanobind/nb_defs.h" with if(nanobind_POPULATED) so the file(WRITE ...) and patch message only execute when nanobind was populated via FetchContent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/pyOpenMS/CMakeLists.txt`:
- Around line 154-165: The current patch uses nanobind_SOURCE_DIR to decide
whether to modify nb_defs.h, which can be set even for an installed nanobind;
change the guard to ensure this only runs for FetchContent-provided nanobind by
testing nanobind_POPULATED (set by FetchContent_MakeAvailable) instead of or in
addition to nanobind_SOURCE_DIR; i.e., wrap the existing logic that reads/writes
"${nanobind_SOURCE_DIR}/include/nanobind/nb_defs.h" with if(nanobind_POPULATED)
so the file(WRITE ...) and patch message only execute when nanobind was
populated via FetchContent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 59f12625-4694-4488-9aef-2585ebdde1b9
📒 Files selected for processing (1)
src/pyOpenMS/CMakeLists.txt
…ompile-time blowup MSVC's optimizer exhibits O(n²) complexity when processing __forceinline directives on large translation units. nanobind defines NB_INLINE as __forceinline on Windows, causing compilation of large binding files (e.g. bind_misc.cpp at 5K lines) to take hours instead of minutes. Patch nb_defs.h after FetchContent to replace __forceinline with plain inline. This has no measurable impact on binary size or runtime performance (confirmed in nanobind discussions/791). Refs: wjakob/nanobind#791 Refs: #8932 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
nanobind_SOURCE_DIR is only set when nanobind is fetched via FetchContent. In the cibuildwheel Windows build, nanobind is installed via pip (build requirement in pyproject.toml), so find_package(nanobind) succeeds and FetchContent is never invoked — making the patch silently no-op. NB_DIR is set by nanobind-config.cmake regardless of install method (pip or FetchContent), so the patch now fires in all cases. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
7 incremental PRs with exact file paths, code snippets, and test commands. Addresses all review feedback: - boost::process is header-only (no cmake COMPONENTS) - DateTime rewrite covers all methods including fromString parser - Complete file list for PR 5a (~20 files) - DBSuitability and InternalCalibration added to PR 4 - UpdateCheck.cpp handled entirely in PR 3 - pyOpenMS build verification in PR 6 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
8e61d4b to
ea9fd82
Compare
Summary
__forceinline→inlineinnb_defs.hafter FetchContent, MSVC onlyBackground
MSVC's optimizer has pathological O(n²) complexity when processing
__forceinlinedirectives on large translation units. nanobind v2.10.0 definesNB_INLINEas__forceinlineon Windows. With our largest binding files (bind_misc.cppat 5K lines,bind_kernel.cppat 4K lines), this causes severe compile-time blowup when any optimization flag (/Os,/O1,/O2) is enabled.Reported improvements from the same fix in other projects: 2h28m → 3m04s (see nanobind#791).
The patch only fires when nanobind is fetched via FetchContent and only on MSVC. It is idempotent (checks for
__forceinlinebefore patching).Related
/Od /Ob0override incibuild.cmakethat was likely a workaround for this same issueTest plan
Patched nanobind nb_defs.h: __forceinline → inline (MSVC compile-time fix)🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation