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

Dynamic app resampling and better performance measurements. #6595

Merged
merged 15 commits into from
May 28, 2023
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@
- [ToggleButtons can now have tooltips][6035].
- [Rendering of tooltips was improved.][6097] Their text is now more vertically
centered and the delay before showing them was extended.
- [Accurate GPU performance measurements have been implemented][6595]. It is
possible now to track both the time spent on both the CPU and the GPU sides.

[3857]: https://github.com/enso-org/enso/pull/3857
[3985]: https://github.com/enso-org/enso/pull/3985
Expand All @@ -224,6 +226,7 @@
[6487]: https://github.com/enso-org/enso/pull/6487
[6341]: https://github.com/enso-org/enso/pull/6341
[6470]: https://github.com/enso-org/enso/pull/6470
[6595]: https://github.com/enso-org/enso/pull/6595

#### Enso Standard Library

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,13 @@ impl super::SpanWidget for Widget {
}

fn new(_: &Config, ctx: &super::ConfigContext) -> Self {
console_log!("NEW");
let display_object = object::Instance::new_named("widget::ListEditor");
let model = Model::new(ctx, &display_object);
let network = frp::Network::new("widget::ListEditor");
Self { display_object, network, model: Rc::new(RefCell::new(model)) }.init_list_updates(ctx)
}

fn configure(&mut self, cfg: &Config, ctx: super::ConfigContext) {
console_log!("CONFIGURE");
let mut model = self.model.borrow_mut();
model.configure(&self.display_object, cfg, ctx);
}
Expand Down
96 changes: 96 additions & 0 deletions lib/rust/data-structures/src/circular_vec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//! Definition of a circular vector, a vector with a constant max size, that if full, keeps its
//! element in a loop.

use std::collections::VecDeque;



/// A vector with a constant max size, that if full, keeps its element in a loop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this line. It does not keep elements, but rather drops the old ones when the capacity is full, doesn't it?

#[derive(Clone, Debug)]
pub struct CircularVecDeque<T> {
capacity: usize,
vec: VecDeque<T>,
}

impl<T> CircularVecDeque<T> {
/// Constructor.
pub fn new(capacity: usize) -> Self {
let vec = VecDeque::with_capacity(capacity);
Self { capacity, vec }
}

/// Check whether the vector is empty.
pub fn is_empty(&self) -> bool {
self.vec.is_empty()
}

/// The capacity of the vector.
pub fn len(&self) -> usize {
self.vec.len()
}

/// Check whether the vector is full.
pub fn is_full(&self) -> bool {
self.len() == self.capacity
}

/// Push a new element at the beginning of the vector. if the vector is full, the last element
/// will be dropped.
pub fn push_front(&mut self, value: T) {
if self.is_full() {
self.vec.pop_back();
}
self.vec.push_front(value);
}

/// Push a new element at the end of the vector. if the vector is full, the first element will
/// be dropped.
pub fn push_back(&mut self, value: T) {
if self.is_full() {
self.vec.pop_front();
}
self.vec.push_back(value);
}

/// Pop the first element of the vector.
pub fn pop_front(&mut self) -> Option<T> {
self.vec.pop_front()
}

/// Pop the last element of the vector.
pub fn pop_back(&mut self) -> Option<T> {
self.vec.pop_back()
}

/// Get the element at the given index.
pub fn get(&self, index: usize) -> Option<&T> {
self.vec.get(index)
}

/// Get a mutable reference to the element at the given index.
pub fn get_mut(&mut self, index: usize) -> Option<&mut T> {
self.vec.get_mut(index)
}

/// get the last element of the vector, if any.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// get the last element of the vector, if any.
/// Get the last element of the vector, if any.

pub fn last(&self) -> Option<&T> {
self.vec.back()
}

/// Run the provided function on the last `n` elements of the vector.
pub fn with_last_n_elems(&mut self, n: usize, mut f: impl FnMut(&mut T)) {
let len = self.len();
let start = len.saturating_sub(n);
for i in start..len {
f(self.vec.get_mut(i).unwrap());
}
}

/// Run the provided function on the `n`-th element of the vector counted from back.
pub fn with_last_nth_elem(&mut self, n: usize, f: impl FnOnce(&mut T)) {
let len = self.len();
if len > n {
f(self.vec.get_mut(len - n - 1).unwrap());
}
}
}
1 change: 1 addition & 0 deletions lib/rust/data-structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
// === Export ===
// ==============

pub mod circular_vec;
pub mod dependency_graph;
pub mod diet;
pub mod hash_map_tree;
Expand Down
1 change: 1 addition & 0 deletions lib/rust/ensogl/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ features = [
'WebGlBuffer',
'WebGlFramebuffer',
'WebGlProgram',
'WebGlQuery',
'WebGlRenderingContext',
'WebGlShader',
'WebGlSync',
Expand Down
12 changes: 6 additions & 6 deletions lib/rust/ensogl/core/src/animation/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ crate::define_endpoints_2! {
on_after_animations(TimeInfo),
on_before_layout(TimeInfo),
on_before_rendering(TimeInfo),
frame_end(TimeInfo),
on_frame_end(TimeInfo),
}
}

Expand All @@ -189,8 +189,8 @@ pub fn on_frame_start() -> enso_frp::Sampler<Duration> {
}

/// Fires at the end of every animation frame.
pub fn frame_end() -> enso_frp::Sampler<TimeInfo> {
LOOP_REGISTRY.with(|registry| registry.frame_end.clone_ref())
pub fn on_frame_end() -> enso_frp::Sampler<TimeInfo> {
LOOP_REGISTRY.with(|registry| registry.on_frame_end.clone_ref())
}

/// Fires before the animations are evaluated.
Expand Down Expand Up @@ -310,7 +310,7 @@ fn on_frame_closure(
let on_after_animations = output.on_after_animations.clone_ref();
let on_before_layout = output.on_before_layout.clone_ref();
let on_before_rendering = output.on_before_rendering.clone_ref();
let frame_end = output.frame_end.clone_ref();
let on_frame_end = output.on_frame_end.clone_ref();
let before_animations = before_animations.clone_ref();
let animations = animations.clone_ref();
let _profiler = profiler::start_debug!(profiler::APP_LIFETIME, "@on_frame");
Expand All @@ -322,10 +322,10 @@ fn on_frame_closure(
.then(move || before_animations.run_all(time_info))
.then(move || fixed_fps_sampler.borrow_mut().run(time_info, |t| animations.run_all(t)))
.then(move || on_after_animations.emit(time_info))
.then(move || frame_end.emit(time_info))
.then(move || on_before_layout.emit(time_info))
.then(move || on_before_rendering.emit(time_info))
.then(move || {
on_before_rendering.emit(time_info);
on_frame_end.emit(time_info);
drop(_profiler);
})
.schedule();
Expand Down
Loading