Improve build time of setting classes#94676
Conversation
|
Workflow [PR], commit [dfc2929] Summary: ❌
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a base class SettingFieldBase for all SettingField* types to improve build time of setting classes by reducing the number of generated lambda functions. The change makes the setting field classes larger (due to virtual tables) but significantly speeds up compilation, reducing build time for Settings.cpp from ~43 seconds to ~15 seconds.
Changes:
- Introduced
SettingFieldBasewith virtual methods for common operations - Made all
SettingField*classes inherit fromSettingFieldBase - Simplified
FieldInfometadata to only store two function pointers instead of many lambdas - Changed
getPath()to returnconst char*and handle empty paths for custom settings
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| src/Core/SettingsFields.h | Introduces SettingFieldBase base class and updates all SettingField* classes to inherit from it with virtual method overrides |
| src/Core/ServerSettings.cpp | Updates getPath() usage to handle empty strings for settings without paths |
| src/Core/BaseSettings.h | Refactors FieldInfo to use two function pointers instead of many lambdas, updates getPath() return type, adds extensive documentation |
Comments suppressed due to low confidence (1)
src/Core/BaseSettings.h:1
- Multiple uses of
const_castthroughout these methods. Consider adding a const-qualified version ofget_data_functionor redesigning to avoid casting away constness, which can lead to undefined behavior if the underlying data is truly const.
#pragma once
|
|
||
| struct SettingFieldBase | ||
| { | ||
| virtual ~SettingFieldBase() {} |
There was a problem hiding this comment.
Virtual destructor should use = default instead of empty braces {} to clearly indicate default behavior and allow compiler optimizations.
| virtual ~SettingFieldBase() {} | |
| virtual ~SettingFieldBase() = default; |
| static ValueType parseValueFromString(const std::string_view str) | ||
| { | ||
| static const String separators=", "; | ||
| constexpr String separators=", "; |
There was a problem hiding this comment.
constexpr String is invalid in C++. Use static const String or static constexpr std::string_view instead.
38ddb47
|
Hi @Algunenano @nickitat — while reviewing this PR I found the following:
Happy to discuss — close anything that's wrong or already addressed. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Improve build time of setting classes
Introduce a base class
SettingFieldBasefor all SettingField##Type classes in order to remove most of the lambda functions inFieldInfo. This makes the classes larger (because of the virtual tables) but speeds up compilation, which is a pain.I also tried to move from using one member per setting inside of ::Data to use a std::vector of SettingFieldBase but this made the code way more complex and slower to build (15->25 seconds).
Comparing Settings.cpp (the largest one) in my local dev machine:
References #58797
Documentation entry for user-facing changes