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

PERF: countCycles doesn't respect options.depth #57

Open
idbrii opened this issue Jul 6, 2022 · 1 comment
Open

PERF: countCycles doesn't respect options.depth #57

idbrii opened this issue Jul 6, 2022 · 1 comment

Comments

@idbrii
Copy link

idbrii commented Jul 6, 2022

inspect can be slow with { depth = 1 } on large tables because countCycles still fully processes the whole table.

inspect.lua/inspect.lua

Lines 304 to 314 in 9c8a68d

local depth = options.depth or (math.huge)
local newline = options.newline or '\n'
local indent = options.indent or ' '
local process = options.process
if process then
root = processRecursive(process, root, {}, {})
end
local cycles = {}
countCycles(root, cycles)

cycles is only used to print the id before a table, but if the additional references aren't printed then the id isn't useful. Definitely doesn't seem worth the cost just to indicate that a value is referenced deeper inside the table. I had cases where inspect(t, { depth = 1 }) took 1000 ms but removing countCycles reduced it to 1 ms.

@kikito
Copy link
Owner

kikito commented Jan 22, 2023

Hello, this could be a good optimisation for inspect. I cannot devote time to implement it right now, feel free to open a pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants