-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Showing a dict can be slow #9481
Comments
Yup. This was my doing... and was why I then opened issue #5709 to try to figure out a consistent API to ask for a limited |
we could create an IOBuffer with a max length, and then catch the write error if it happens. not sure if that is the best solution, however. |
@vtjnash except for the failing early there's already a maxsize for IOBuffer (at least I don't think this fails early?). In fact there's already a sprint with a size option, though it's unclear to me if the intention was for this to be a sizehint or a maxsize:
|
This works pretty well as a stop-gap: diff --git a/base/dict.jl b/base/dict.jl
index a496b5d..1fed3f5 100644
--- a/base/dict.jl
+++ b/base/dict.jl
@@ -97,9 +97,11 @@ function showdict{K,V}(io::IO, t::Associative{K,V}; limit::Bo
print(io, key)
print(io, " => ")
- val = sprint(show, v)
if limit
+ val = with_output_limit(()->sprint(show, v))
val = _truncate_at_width_or_chars(val, cols - keylen, "\r\n")
+ else
+ val = sprint(show, v)
end
print(io, val)
end |
The
showkv
function indict.jl
(latest master) contains the following code:If
v
is "large", the above can be arbitrarily slow due to thesprint(show, v)
part.Below an example showing the problem from the REPL:
Increase N as necessary.
The text was updated successfully, but these errors were encountered: