-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add thread local caching to thread_stack_bounds
Summary: Original Author: [email protected] Original Git: 4fc57f3 Original Reviewed By: tmikov Original Revision: D66839832 To improve performance in situations where the runtime is repeatedly called from different threads, add a second level of caching for the stack bounds in a `thread_local` in OSCompat. Only if this cache fails will we actually fall back to the platform-specific API calls. The user-facing API doesn't change, we just split the `thread_stack_bounds` code into a public function and an internal `_impl` function. Reviewed By: tmikov Differential Revision: D66890656 fbshipit-source-id: 901c5484ed95d3ec0a8611aee87f4d4b9fbd6337
- Loading branch information
1 parent
33dfc8f
commit 568b1c9
Showing
6 changed files
with
62 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "hermes/Support/OSCompat.h" | ||
|
||
namespace hermes { | ||
namespace oscompat { | ||
|
||
std::pair<const void *, size_t> thread_stack_bounds(unsigned gap) { | ||
// Avoid calling into the platform-specific code if we can cache the result | ||
// on a per-thread basis. | ||
|
||
// The cached result of thread_stack_bounds(). | ||
static thread_local std::pair<const void *, size_t> cachedBounds{nullptr, 0}; | ||
|
||
std::pair<const void *, size_t> bounds = cachedBounds; | ||
|
||
if (LLVM_UNLIKELY(!bounds.first)) { | ||
cachedBounds = bounds = detail::thread_stack_bounds_impl(); | ||
} | ||
|
||
// Adjust for the gap here to allow caching with multiple gaps. | ||
auto [high, size] = bounds; | ||
return {high, gap < size ? size - gap : 0}; | ||
} | ||
|
||
} // namespace oscompat | ||
} // namespace hermes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters