Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化sharetable更新 #1208

Merged
merged 1 commit into from
Jun 24, 2020
Merged
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
43 changes: 18 additions & 25 deletions lualib/skynet/sharetable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,12 @@ local function resolve_replace(replace_map)

local function match_value(v)
assert(v ~= nil)
if v == RECORD then
if record_map[v] or is_sharedtable(v) then
return
end

local tv = type(v)
local f = match[tv]
if record_map[v] or is_sharedtable(v) then
return
end

if f then
record_map[v] = true
f(v)
Expand Down Expand Up @@ -364,7 +360,7 @@ local function resolve_replace(replace_map)
end

local level = info.level
local curco = info.curco or coroutine.running()
local curco = info.curco
if not level then
return
end
Expand All @@ -390,7 +386,7 @@ local function resolve_replace(replace_map)
end

local stack_values_tmp = {}
local function match_thread(co)
local function match_thread(co, level)
-- match stackvalues
local n = stackvalues(co, stack_values_tmp)
for i=1,n do
Expand All @@ -399,40 +395,37 @@ local function resolve_replace(replace_map)
match_value(v)
end

-- match callinfo
local level = 1
-- jump the fucntion from sharetable.update to top
local is_self = coroutine.running() == co
if is_self then
while true do
local info = getinfo(co, level, "uf")
level = level + 1
if not info then
level = 1
break
elseif info.func == sharetable.update then
break
end
end
end

level = level or 1
while true do
local info = getinfo(co, level, "uf")
if not info then
break
end
info.level = is_self and level + 1 or level
info.level = level
info.curco = co
match_funcinfo(info)
level = level + 1
end
end

local function prepare_match()
local co = coroutine.running()
record_map[co] = true
record_map[match] = true
record_map[RECORD] = true
record_map[record_map] = true
record_map[insert_replace] = true
record_map[resolve_replace] = true
assert(getinfo(co, 3, "f").func == sharetable.update)
match_thread(co, 5) -- ignore match_thread and match_funcinfo frame
end

match["table"] = match_table
match["function"] = match_function
match["userdata"] = match_userdata
match["thread"] = match_thread

prepare_match()
match_internmt()

local root = debug.getregistry()
Expand Down