Skip to content

Commit

Permalink
cut unconditional string-key indirection in FormattedKeyHolder
Browse files Browse the repository at this point in the history
Summary:
There are two optimizations within this one change in return type, assuming that the callee `FormattedKeyHolder::getFormattedKeyWithExtra` is not inline-expanded into the caller.

* An indirection occurs within the callee, but the indirection would be needed only in the caller and only conditionally in a rare, slow path. If the callee is not inline-expanded into the caller, there may be no opportunity for the compiler to make the indirection itself conditional just like the usage of the indirection. This change returns the reference from the callee before indirection and allows the caller to indirect only conditionally.

* The return type of the callee is too large to be passed via registers in the common ABIs, and so must be spilled to the stack. The maximum size is 2 pointers, but the return type is 3 pointers in size. This change modifies the return type to be 2 pointers in size, allowing the return value to be passed via registers and to skip the stack.

Reviewed By: dddmello, DenisYaroshevskiy

Differential Revision: D66175277

fbshipit-source-id: 7f3e7d8d48c40b6201458777b6702197168e307c
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Jan 5, 2025
1 parent 48a9884 commit 6de11b8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fb303/ThreadCachedServiceData.h
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,13 @@ class FormattedKeyHolder {
/**
* Given a subkey (e.g. "bar"), returns the full stat key (e.g. "foo.bar")
* and registers the stats export types if not registered already.
*
* Key is returned as a reference v.s. as a string_view since callers need it
* only in the cold path. This allows passing the return value in registers
* v.s. via the stack and defers the dereference operation to the cold path.
*/
template <typename... Args>
std::pair<std::string_view, std::reference_wrapper<CachedType>>
std::pair<const std::string&, std::reference_wrapper<CachedType>>
getFormattedKeyWithExtra(Args&&... subkeys) {
auto& v = getFormattedEntry(std::forward<Args>(subkeys)...);
return {*v.key, v.cached};
Expand Down

0 comments on commit 6de11b8

Please sign in to comment.