-
Notifications
You must be signed in to change notification settings - Fork 15
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
Honor MAX_DISPLAY_ENTRIES
when inspecting variables
#629
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
for char in elt.chars() { | ||
if display_value.len() >= MAX_DISPLAY_VALUE_LENGTH { | ||
is_truncated = true; | ||
break 'outer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat syntax for long breaks
let mut out: Vec<Variable> = vec![]; | ||
let n = unsafe { Rf_xlength(value) }; | ||
|
||
let list = List::new(value)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// We need to be careful when truncating the string, we don't want to return invalid | ||
// UTF8 sequences. `chars` makes sure we are not splitting a UTF8 character in half. | ||
// See also https://doc.rust-lang.org/book/ch08-02-strings.html#slicing-strings | ||
fn truncate_chars(value: String, len: usize) -> (bool, String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC String::truncate()
would be unsafe here because it takes a byte offset, not a number of chars? I see in the docs:
Panics if new_len does not lie on a char boundary.
Tricky!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly! We either need to find the char index to truncate using the char_indices()
iterator or make a copy like we do here.
crates/ark/src/variables/variable.rs
Outdated
@@ -1779,6 +1818,14 @@ mod tests { | |||
}) | |||
} | |||
|
|||
fn inspect_from_expr(code: &str) -> Vec<Variable> { | |||
let env = harp::parse_eval_global("new.env()").unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably worth adding an Environment
method at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 840a877, let me know what you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable
This PR fixes some performance related issues that involve the variables pane.
Addressing:
The goal is to have the following scenarios working fine in positron:
Note: When testing it's important to use a Release version of ark. In my tests, with debug can be 20x slower in such cases - probably for the tail recursion optimizations important for the object size computation.
Not fixed in this PR:
model
from Positron lags when running a model on big data positron#4636 takes about 1s. I think a lot of this time is computing the objects size - because of the deeply nested object.