googleapis / googleapis/google-cloud-cpp
Optimize initial `OptionSpan`
- Langage dominant
- C++
- Étoiles
- 659
- Forks
- 462
- Merge moyen
- 1 j 2 h
- PR mergées (30 j)
- 89
Description
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_;
};
```
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par retracer comment chaque *Client construit OptionsSpan et comment Options et ImmutableOptions stockent et récupèrent actuellement les valeurs. Évaluez la conception proposée de OptionsImpl et du fallback partagé par rapport au comportement de copie existant ; le travail est terminé lorsque les options initiales évitent la copie implicite tout en préservant la sémantique de recherche des options.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- cpp
- Domaine
- backend-api-design, performance
- Type d'issue
- Refactorisation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100