Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lute/runtime/include/lute/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "lute/ref.h"

#include "Luau/Variant.h"
#include "Luau/VecDeque.h"

#include <atomic>
#include <condition_variable>
Expand Down Expand Up @@ -80,7 +81,7 @@ struct Runtime
std::mutex dataCopyMutex;
std::unique_ptr<lua_State, void (*)(lua_State*)> dataCopy;

std::vector<ThreadToContinue> runningThreads;
Luau::VecDeque<ThreadToContinue> runningThreads;

private:
std::mutex continuationMutex;
Expand Down
2 changes: 1 addition & 1 deletion lute/runtime/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RuntimeStep Runtime::runOnce()
return StepEmpty{};

auto next = std::move(runningThreads.front());
runningThreads.erase(runningThreads.begin());
runningThreads.pop_front();

next.ref->push(GL);
lua_State* L = lua_tothread(GL, -1);
Expand Down
32 changes: 32 additions & 0 deletions tools/profile.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local task = require("@lute/task")

local started = os.clock()

local amount = 100000
local batches = 5
local per_batch = amount / batches

for current = 1, batches do
local thread = coroutine.running()

print(`Batch {current} / {batches}`)

for i = 1, per_batch do
--print("Spawning thread #" .. i)
task.spawn(function()
task.wait(0.1)
--_TEST_ASYNC_WORK(0.1)
if i == per_batch then
print("Last thread in batch #" .. current)
assert(coroutine.status(thread) == "suspended", `Thread {i} has status {coroutine.status(thread)}`)
task.spawn(thread)
end
end)
end

coroutine.yield()
end
local took = os.clock() - started
print(`Spawned {amount} sleeping threads in {took}s`)

return -1
4 changes: 4 additions & 0 deletions tools/profile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
DEFAULT_SCRIPTNAME=${1:-profile.luau}
echo "profiling $DEFAULT_SCRIPTNAME"
xctrace record --template 'Time Profiler' --launch -- ./build/xcode/debug/lute/cli/lute $DEFAULT_SCRIPTNAME