Fixed a possible script exhaustion error, which occurred when you had over 100 wait loops running at the same time - I didn’t know about this because, well, I don’t have 100 wait loops running at once lol.
Optimized code overall - it now runs 5x faster than the previous version
local function Loop(self)
while true do
--doing something works!
self.DATA:Wait(0.01) end
end
local function Display(self)
while true do
--runs once and breaks loop
self.DATA:Wait(0.01) end
end
local function Clean(self)
while true do
--this one also runs good
self.DATA:Wait(0.01) end
end
function obj.new(DATA)
local self = setmetatable({}, obj)
coroutine.wrap(Loop)(self)
coroutine.wrap(Display)(self)
coroutine.wrap(Clean)(self)
return self
end
I know the Display loop works because if I replace it with normal wait(), it works good and doesnt break.
Hey!
I’ve actually noticed this issue yesterday and was up till 3 AM trying to fix it, but I only managed to address the issue today. Can you update your module’s source to the newest version, and see if your issue has been addressed?
EDIT: Seems like it wasn’t fixed according to my testing. Looking into it!
Glad you figured out a solution. I will check it out when I get back on. But otherwise, exceptional job making this module. Looking forward to more of your potential projects.
So I wrote my own custom yield script, just for fun, and after doing a benchmark it seems to be functioning better than this one.
Benchmark script:
-- // By StrategicPlayZ \\ --
local FastWait = require(workspace.FastWait)
local CustomWait = require(workspace.CustomWait)
for i = 5,1,-1 do
print("[STARTING BENCHMARK IN " .. i .. "s]")
wait(1)
end
local total = 50000
local wait_time = 1
local benchmark_func = FastWait do
print("...[BENCHMARK BEGIN]...")
local num_failed = 0
local total_wait = 0
local highest_wait = 0
local lowest_wait = math.huge
local completed
game:GetService("RunService").Stepped:Wait()
for index = 1, total do
coroutine.wrap(function()
local taken_time = benchmark_func(wait_time)
if ((taken_time > (wait_time + 0.04)) or (taken_time < (wait_time - 0.04))) then
num_failed += 1
end
if (taken_time > highest_wait) then
highest_wait = taken_time
end
if (taken_time < lowest_wait) then
lowest_wait = taken_time
end
total_wait += taken_time
completed()
end)()
end
do
local n = 0
function completed()
n += 1
if (n ~= total) then return end
local average_wait = (total_wait / total)
print("[% NUM FAILED]: " .. (num_failed / total * 100) .. "%")
print("[AVERAGE WAIT]: " .. average_wait)
print("[HIGHEST WAIT]: " .. highest_wait)
print("[LOWEST WAIT]: " .. lowest_wait)
end
end
end
After slightly altering my code, the end result was this:
Yours
Mine
All I altered was the for loop in the Stepped event, editing it from 10,000 to 100,000. By doing so, it effectively unyielded all the yields at once, rather than taking 5 Stepped events to unyield them, since it only unyielded a maximum of 10,000 per Stepped. I set this limit with script exhaustion time in mind, which your script does not take into account for. By raising the for loop limit, this module effectively addresses the flawed benchmark.
Either way, I will not be raising the unyield limit from 10,000 since as stated, it could cause havoc when you have 100+ while true do wait() end loops.
This seems like an issue of having different hardware in that case. I don’t really bother comparing stuff at such a level, since it’s very prone to illusionary and misleading results - the only reason I compared this module with Roblox’s is that the margin of error is small enough in comparison to Roblox’s “failure rate”, and as such the margin of error can be ignored completely. With modules that provide very similar results with only the slightest differences, it’s hard to say what’s truly the better option. I’ll run both scripts though the micro-profiler and also boatbomber’s benchmarker plugin instead, as they provide with more accurate results.
That’s weird. I’ve confirmed this behavior just now, and it does seem like wait(0) or wait() achieve this effect. An easy solution would be to just do wait(0.01) for now. I’ll fix this next update and clamp the minimum value to 0.01.
Best != perfect. Don’t mix up the words. Thus far I have not seen any solution which other modules offer better solutions than this module. You mentioned your own module with no other relevancy other than to imply it is better than mine because the issue mentioned above does not occur with yours. Before you state that you didn’t say that, I meant imply. Intent is enough, and saying that was not your intent would be delusional.