Skip to content

Commit

Permalink
Avoid computing the size of child objects when inspecting variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dfalbel committed Nov 15, 2024
1 parent 2fbc94a commit 15b4c4f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions crates/ark/src/variables/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,15 +541,15 @@ impl PositronVariable {
BindingValue::Active { .. } => Self::from_active_binding(display_name),
BindingValue::Promise { promise } => Self::from_promise(display_name, promise.sexp),
BindingValue::Altrep { object, .. } | BindingValue::Standard { object, .. } => {
Self::from(display_name.clone(), display_name, object.sexp)
Self::from(display_name.clone(), display_name, object.sexp, true)
},
}
}

/**
* Create a new Variable from an R object
*/
fn from(access_key: String, display_name: String, x: SEXP) -> Self {
fn from(access_key: String, display_name: String, x: SEXP, compute_size: bool) -> Self {
let WorkspaceVariableDisplayValue {
display_value,
is_truncated,
Expand All @@ -560,14 +560,16 @@ impl PositronVariable {
} = WorkspaceVariableDisplayType::from(x, true);

let kind = Self::variable_kind(x);

let size = match RObject::view(x).size() {
Ok(size) => size as i64,
Err(err) => {
log::warn!("Can't compute size of object: {err}");
0
},
};
let mut size = 0;
if compute_size {
size = match RObject::view(x).size() {
Ok(size) => size as i64,
Err(err) => {
log::warn!("Can't compute size of object: {err}");
0
},
};
}

Self {
var: Variable {
Expand Down Expand Up @@ -1126,7 +1128,7 @@ impl PositronVariable {
.map(|(i, value)| {
let (_, display_name) =
truncate_chars(names.get_unchecked(i as isize), MAX_DISPLAY_VALUE_LENGTH);
Self::from(i.to_string(), display_name, value).var()
Self::from(i.to_string(), display_name, value, false).var()
})
.collect();

Expand Down Expand Up @@ -1298,7 +1300,7 @@ impl PositronVariable {
String::from(RSymbol::new_unchecked(tag))
};

out.push(Self::from(i.to_string(), display_name, CAR(pairlist)).var());
out.push(Self::from(i.to_string(), display_name, CAR(pairlist), false).var());

pairlist = CDR(pairlist);
i = i + 1;
Expand Down Expand Up @@ -1412,7 +1414,7 @@ impl PositronVariable {
let slot_symbol = r_symbol!(display_name);
let slot: RObject = harp::try_catch(|| R_do_slot(value, slot_symbol).into())?;
let access_key = display_name.clone();
out.push(PositronVariable::from(access_key, display_name, slot.sexp).var());
out.push(PositronVariable::from(access_key, display_name, slot.sexp, false).var());
}
}

Expand Down Expand Up @@ -1487,7 +1489,7 @@ impl PositronVariable {
let access_key = format!("custom-{i}-{name_len}-{access_name}");

let display_name = name.clone().unwrap_or(format!("[[{}]]", i + 1));
Self::from(access_key, display_name, x).var()
Self::from(access_key, display_name, x, false).var()
})
.collect();

Expand Down

0 comments on commit 15b4c4f

Please sign in to comment.