Skip to content
Snippets Groups Projects
Commit 1aa19dab authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Re-use the result of Runtime::getWorkerId() when possible

Runtime::getWorkerId() may be an expensive operation, hence re-use the
result of the method when possible.
parent 56e0fdb6
No related branches found
No related tags found
No related merge requests found
......@@ -40,12 +40,13 @@ class MemoryManager {
if (likely(poped)) return memory;
// Fallback to memory-stealing.
const workerid_t myWorkerId = Runtime::getWorkerId();
const workerid_t startWorkerId = Runtime::rand() % workerCount;
for (workerid_t i = 0; i < workerCount; ++i) {
workerid_t victim = (startWorkerId + i) % workerCount;
// Don't steal from ourselves.
if (unlikely(victim == Runtime::getWorkerId())) continue;
if (unlikely(victim == myWorkerId)) continue;
poped = queues[victim]->popTop(&memory);
if (poped) return memory;
......
......@@ -54,6 +54,7 @@ auto WsScheduler::nextFiber() -> Fiber* {
return fiber;
}
const workerid_t myWorkerId = Runtime::getWorkerId();
const workerid_t workerCount = runtime.getWorkerCount();
workerid_t startWorkerId = Runtime::rand() % workerCount;
// TODO: See how reducing the loop bound affects things.
......@@ -61,7 +62,7 @@ auto WsScheduler::nextFiber() -> Fiber* {
workerid_t victim = (startWorkerId + i) % workerCount;
// Don't steal from ourselves.
if (unlikely(victim == Runtime::getWorkerId())) continue;
if (unlikely(victim == myWorkerId)) continue;
poped = queues[victim]->popTop(&fiber);
if (poped) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment