forked from osmarks/potatOS
performance improvements, probably
This commit is contained in:
@@ -192,7 +192,7 @@ function serialize(obj)
|
||||
|
||||
-- Internal recursive function.
|
||||
local function serialize(obj)
|
||||
yield()
|
||||
--yield()
|
||||
local t = type(obj)
|
||||
if t == "table" then
|
||||
local len = #obj
|
||||
@@ -277,7 +277,7 @@ function deserialize(ser)
|
||||
end
|
||||
|
||||
local function deserializeValue()
|
||||
yield()
|
||||
--yield()
|
||||
local t = getchar()
|
||||
idx = idx + 1
|
||||
if t == "t" then
|
||||
|
@@ -10,7 +10,7 @@ if process then
|
||||
process.spawn(function()
|
||||
while true do
|
||||
local event = {coroutine.yield()}
|
||||
entropy = {
|
||||
local entropy = {
|
||||
entropy,
|
||||
event[1],
|
||||
tostring(event[2]),
|
||||
@@ -20,7 +20,7 @@ if process then
|
||||
tostring({}),
|
||||
math.random()
|
||||
}
|
||||
entropy = table.concat(entropy, "|")
|
||||
local entropy = table.concat(entropy, "|")
|
||||
|
||||
if #entropy > maxEntropySize then
|
||||
state = sha256.digest(entropy)
|
||||
|
27
src/main.lua
27
src/main.lua
@@ -653,12 +653,12 @@ end
|
||||
-- Powered by SPUDNET, the simple way to include remote debugging services in *your* OS. Contact Gollark today.
|
||||
local function websocket_remote_debugging()
|
||||
if not http or not http.websocket then return "Websockets do not actually exist on this platform" end
|
||||
|
||||
|
||||
local ws
|
||||
|
||||
local function send_packet(msg)
|
||||
--ws.send(safe_serialize(msg))
|
||||
ws.send(safe_json_serialize(msg))
|
||||
ws.send(safe_json_serialize(msg), true)
|
||||
end
|
||||
|
||||
local function send(data)
|
||||
@@ -667,7 +667,7 @@ local function websocket_remote_debugging()
|
||||
|
||||
local function connect()
|
||||
if ws then ws.close() end
|
||||
ws, err = http.websocket "wss://spudnet.osmarks.net/v4"
|
||||
ws, err = http.websocket "wss://spudnet.osmarks.net/v4?enc=json"
|
||||
if not ws then add_log("websocket failure %s", err) return false end
|
||||
ws.url = "wss://spudnet.osmarks.net/v4"
|
||||
|
||||
@@ -689,7 +689,7 @@ local function websocket_remote_debugging()
|
||||
|
||||
local function recv()
|
||||
while true do
|
||||
local e, u, x = os.await_event "websocket_message"
|
||||
local e, u, x, b = os.await_event "websocket_message"
|
||||
if u == ws.url then return json.decode(x) end
|
||||
end
|
||||
end
|
||||
@@ -724,6 +724,7 @@ local function websocket_remote_debugging()
|
||||
_G.wsrecv = recv
|
||||
_G.wssend = send
|
||||
_G.envrequire = require
|
||||
_G.rawws = ws
|
||||
add_log("SPUDNET command - %s", code)
|
||||
local f, errr = load(code, "@<code>", "t", _G)
|
||||
if f then -- run safely in background, send back response
|
||||
@@ -873,7 +874,7 @@ local function verify_update_sig(hash, sig)
|
||||
end
|
||||
|
||||
-- Project PARENTHETICAL SEMAPHORES - modernized updater system with delta update capabilities, not-pastebin support, signing
|
||||
local function process_manifest(url, force)
|
||||
local function process_manifest(url, force, especially_force)
|
||||
local h = assert(http.get(url, nil, true)) -- binary mode, to avoid any weirdness
|
||||
local txt = h.readAll()
|
||||
h.close()
|
||||
@@ -909,10 +910,15 @@ local function process_manifest(url, force)
|
||||
add_log "update manifest parsed"
|
||||
print "Update manifest parsed"
|
||||
|
||||
local current_manifest = registry.get "potatOS.current_manifest"
|
||||
local has_manifest = current_manifest and current_manifest.files and not especially_force
|
||||
|
||||
for file, hash in pairs(data.files) do
|
||||
if fs.isDir(file) then fs.delete(file) end
|
||||
if not fs.exists(file) then print("missing", file) add_log("nonexistent %s", file) table.insert(needs, file)
|
||||
elseif (data.sizes and data.sizes[file] and data.sizes[file] ~= fs.getSize(file)) or hexize(sha256(fread(file))) ~= hash then
|
||||
elseif (data.sizes and data.sizes[file] and data.sizes[file] ~= fs.getSize(file))
|
||||
or (has_manifest and ((current_manifest.files[file] and current_manifest.files[file] ~= hash) or not current_manifest.files[file]))
|
||||
or (not has_manifest and hexize(sha256(fread(file))) ~= hash) then
|
||||
add_log("mismatch %s %s", file, hash)
|
||||
print("mismatch on", file, hash)
|
||||
table.insert(needs, file)
|
||||
@@ -1431,7 +1437,12 @@ else
|
||||
potatOS.registry.set(key, value)
|
||||
end
|
||||
]],
|
||||
["/rom/heavlisp_lib/stdlib.hvl"] = fproxy "stdlib.hvl"
|
||||
["/rom/heavlisp_lib/stdlib.hvl"] = fproxy "stdlib.hvl",
|
||||
["/rom/programs/ctime.lua"] = [[
|
||||
for _, info in pairs(process.list()) do
|
||||
print(("%s %f %f"):format(info.name or info.ID, info.execution_time, info.ctime))
|
||||
end
|
||||
]]
|
||||
}
|
||||
|
||||
for _, file in pairs(fs.list "bin") do
|
||||
@@ -1450,7 +1461,6 @@ end
|
||||
local API_overrides = {
|
||||
potatOS = potatOS,
|
||||
process = process,
|
||||
-- bigfont = bigfont,
|
||||
json = json,
|
||||
os = {
|
||||
setComputerLabel = function(l) -- to make sure that nobody destroys our glorious potatOS by breaking the computer
|
||||
@@ -1460,6 +1470,7 @@ end
|
||||
very_shutdown = function() osshutdown() end,
|
||||
await_event = os.await_event
|
||||
},
|
||||
_VERSION = _VERSION,
|
||||
polychoron = polychoron, -- so that nested instances use our existing process manager system, as polychoron detects specifically *its* presence and not just generic "process"
|
||||
}
|
||||
|
||||
|
@@ -161,6 +161,7 @@ local function tick(proc, event)
|
||||
local ok, res = coroutineresume(proc.coroutine, table.unpack(event))
|
||||
local end_time = time()
|
||||
proc.execution_time = end_time - start_time
|
||||
proc.ctime = proc.ctime + end_time - start_time
|
||||
if not ok then
|
||||
if proc.error_handler then
|
||||
proc.error_handler(res)
|
||||
@@ -210,7 +211,8 @@ function process.spawn(fn, name, extra)
|
||||
status = process.statuses.OK,
|
||||
ID = this_ID,
|
||||
parent = process.running,
|
||||
["function"] = fn
|
||||
["function"] = fn,
|
||||
ctime = 0
|
||||
}
|
||||
|
||||
if extra then for k, v in pairs(extra) do proc[k] = v end end
|
||||
|
@@ -860,6 +860,8 @@ function fs.complete( sPath, sLocation, bIncludeFiles, bIncludeDirs )
|
||||
return tEmpty
|
||||
end
|
||||
|
||||
potatOS.add_log("[BIOS] primary function defns")
|
||||
|
||||
-- Load APIs
|
||||
local bAPIError = false
|
||||
local tApis = fs.list( "rom/apis" )
|
||||
@@ -1053,6 +1055,8 @@ local function run_shell()
|
||||
term.clear()
|
||||
term.setCursorPos(1, 1)
|
||||
potatOS.add_log "starting user shell"
|
||||
for _, proc in pairs(process.list()) do
|
||||
end
|
||||
os.run( {}, sShell )
|
||||
end
|
||||
|
||||
@@ -1231,6 +1235,7 @@ function bin.dump()
|
||||
end
|
||||
|
||||
function bin.get(k)
|
||||
potatOS.add_log("asked to fetch %s", k)
|
||||
return localbin[k] or bin.dump()[k]
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user