googleapis / googleapis/google-cloud-cpp
Optimize initial `OptionSpan`
- 主要语言
- C++
- 星标
- 659
- 派生
- 462
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 89
描述
Every request in a `*Client` starts with something like:
```cc
google::cloud::internal::OptionsSpan span(std::move(options), options_);
```
The `options_` member variable never changes value. We should avoid the implicit copy from these options. If we can hold them as a `std::shared_ptr` then maybe `ImmutableOptions` can become a class that holds two `Options`, one by value (initialized via move) and a `std::shared_ptr<>` with the remaining values.
Something like:
```cc
class internal::OptionsImpl { // Similar to the Options class today
public:
template auto get() const { ... }
// has() and get() rolled into a single operation.
template std::pair find() const { ... }
};
class internal::ImmutableOptions {
public:
template auto get() const {
auto [has, value] = impl_.find();
if (has) return *value;
return fallback_.get();
}
// No set or unset member functions.
private:
OptionsImpl impl_;
std::shared_ptr fallback_;
};
class Options {
private:
OptionsImpl impl_;
};
```
贡献指南
调研方向
首先跟踪每个 *Client 如何构造 OptionsSpan,以及 Options 和 ImmutableOptions 当前如何存储和检索值。根据现有的复制行为,评估拟议的 OptionsImpl 和共享 fallback 设计;当初始选项避免隐式复制,同时保留选项查找语义时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- cpp
- 领域
- backend-api-design, performance
- Issue 类型
- 重构
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100