Implement batched updates

No docs yet, more testing needed.
This commit is contained in:
Aaron Smith 2023-10-27 16:47:49 +01:00
parent 7d82fe353e
commit ec998ccbc8
6 changed files with 123 additions and 10 deletions

View file

@ -6,6 +6,7 @@ local source = vide.source
local derive = vide.derive
local indexes = vide.indexes
local values = vide.values
local batch = vide.batch
local cleanup = vide.cleanup
local create = vide.create
@ -132,30 +133,51 @@ ROOT_BENCH("update 1->1->1->1...1000 graph", function()
end
end)
-- todo: crashes at 1k
-- todo: repeat with batching
ROOT_BENCH("update 1000->1 graph", function()
-- todo: why does it hang at 1k? it didn't before
ROOT_BENCH("update 500->1 graph", function()
local srcs = {}
for i = 1, 800 do
for i = 1, 500 do
srcs[i] = source(0)
end
derive(function()
for i = 1, 800 do
for i = 1, 500 do
srcs[i]()
end
return false
end)
for i = 1, START(1) do
for idx = 1, 800 do
for idx = 1, 500 do
srcs[idx](i)
end
end
end)
-- todo: optimize, repeat with batching
ROOT_BENCH("update 1000x 1->1 common extern. graph", function()
ROOT_BENCH("update 1000->1 graph (batched)", function()
local srcs = {}
for i = 1, 1000 do
srcs[i] = source(0)
end
derive(function()
for i = 1, 1000 do
srcs[i]()
end
return false
end)
for i = 1, START(1) do
batch(function()
for idx = 1, 1000 do
srcs[idx](i)
end
end)
end
end)
-- todo: optimize this case
ROOT_BENCH("update 1000 1->1 common extern. graph", function()
local ext = source(-1)
local srcs = {}

View file

@ -1800,6 +1800,49 @@ TEST("changed()", wrap_root(function()
end
end))
TEST("batch()", wrap_root(function()
local source = vide.source
local derive = vide.derive
local batch = vide.batch
do CASE "child evaluation halted"
local a = source(0)
local count = { b = 0, b2 = 0, c = 0 }
local b = derive(function()
count.b += 1
return a() + 1
end)
local b2 = derive(function()
count.b2 += 1
return a() + 2
end)
local c = derive(function()
count.c += 1
return b() + b2()
end)
batch(function()
a(1)
CHECK(count.b == 1)
CHECK(count.b2 == 1)
CHECK(count.c == 1)
end)
CHECK(count.b == 2)
CHECK(count.b2 == 2)
CHECK(count.c == 2)
CHECK(b() == 2)
CHECK(c() == 5)
end
-- todo: test batch call in recursive set
end))
TEST("read()", wrap_root(function()
local source = vide.source
local effect = vide.effect