diff options
| author | kraibse <33869366+kraibse@users.noreply.github.com> | 2026-11-02 15:39:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-02 15:39:20 +0100 |
| commit | ce1b1de6f1beed36958368f89cda466937ff9716 (patch) | |
| tree | e3f6d670018b57004915e69d1fc741b4efecb325 /src/common/fiber.cpp | |
| parent | a407703f6d29a5ab73328b4ededb12cf29b2758d (diff) | |
| parent | c0cb3325e22756edb65c87d33ef298349ade0ad3 (diff) | |
Merge pull request #291 from Djihads80/nx2-experimental
[Update] Bring the mainline release up to speed with the performance updates from nx2-experimental
Diffstat (limited to 'src/common/fiber.cpp')
| -rw-r--r-- | src/common/fiber.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/common/fiber.cpp b/src/common/fiber.cpp index 08558a0026..613ac97e22 100644 --- a/src/common/fiber.cpp +++ b/src/common/fiber.cpp @@ -25,8 +25,10 @@ struct Fiber::FiberImpl { FiberImpl() {} u32 canary_1 = CANARY_VALUE; - std::array<u8, DEFAULT_STACK_SIZE> stack; - std::array<u8, DEFAULT_STACK_SIZE> rewind_stack; + // Left uninitialized: the host gives a stack's pages memory only as they are used. Zero-filled + // std::arrays (and a second stack nothing switched to) made every fiber, one per guest thread, + // hold 4 MiB: ~750 MiB for title 1's ~190 threads. + std::unique_ptr<u8[]> stack; u32 canary_2 = CANARY_VALUE; boost::context::detail::fcontext_t context{}; @@ -38,7 +40,6 @@ struct Fiber::FiberImpl { std::shared_ptr<Fiber> previous_fiber; u8* stack_limit = nullptr; - u8* rewind_stack_limit = nullptr; bool is_thread_fiber = false; bool released = false; }; @@ -49,10 +50,10 @@ void Fiber::SetRewindPoint(std::function<void()>&& rewind_func) { Fiber::Fiber(std::function<void()>&& entry_point_func) : impl{std::make_unique<FiberImpl>()} { impl->entry_point = std::move(entry_point_func); - impl->stack_limit = impl->stack.data(); - impl->rewind_stack_limit = impl->rewind_stack.data(); + impl->stack.reset(new u8[DEFAULT_STACK_SIZE]); + impl->stack_limit = impl->stack.get(); u8* stack_base = impl->stack_limit + DEFAULT_STACK_SIZE; - impl->context = boost::context::detail::make_fcontext(stack_base, impl->stack.size(), [](boost::context::detail::transfer_t transfer) -> void { + impl->context = boost::context::detail::make_fcontext(stack_base, DEFAULT_STACK_SIZE, [](boost::context::detail::transfer_t transfer) -> void { auto* fiber = static_cast<Fiber*>(transfer.data); ASSERT(fiber && fiber->impl && fiber->impl->previous_fiber && fiber->impl->previous_fiber->impl); ASSERT(fiber->impl->canary_1 == CANARY_VALUE); |
