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

other: slightly reduce the CPU time spent for draws #918

Merged
merged 3 commits into from
Nov 29, 2022

Conversation

ClementTsang
Copy link
Owner

@ClementTsang ClementTsang commented Nov 28, 2022

Description

A description of the change, what it does, and why it was made. If relevant (such as any change that modifies the UI), please provide screenshots of the changes:

Slightly reduces CPU time spent on drawing through two small changes:

  • Group together datasets when drawing.
  • Optimize truncate_text a bit.

The first change results in graphs with a lot of stacked datasets like the "all" CPU graph looking like this instead:

image

(For small graphs with few/one dataset, it looks the same):

image

We can replicate the old effect by switching layers on each draw, but I'm not sure if it's better or worse.

Perfromance-wise can see the general effects through flamegraphs (cargo flamegraph --bin btm, with debug = true and strip = false):

Before the change, drawing took almost 40% of the flamegraph time (measured over ~30 minutes):

image

After, it's taking only about 14% (also ~30 minutes):

image

The other usage from the flamegraph is about the same, so it should hopefully be a reasonable comparison. Running the pre-change and post-change binaries together also shows less CPU time spent on the post-change binary.

Issue

If applicable, what issue does this address?

Closes: #

Testing

If relevant, please state how this was tested. All changes must be tested to work:

If this is a code change, please also indicate which platforms were tested:

  • Windows
  • macOS
  • Linux

Checklist

If relevant, ensure the following have been met:

  • Areas your change affects have been linted using rustfmt (cargo fmt)
  • The change has been tested and doesn't appear to cause any unintended breakage
  • Documentation has been added/updated if needed (README.md, help menu, doc pages, etc.)
  • The pull request passes the provided CI pipeline
  • There are no merge conflicts
  • If relevant, new tests were added (don't worry too much about coverage)

We used to draw each data set separately as a new canvas. Now, in one
canvas, we draw all datasets.

Note that this changes how dataset  lines are drawn - rather than
drawing one on top of another, it now draws kinda all at once. This
effect is *kinda* a bit better IMO, but it might also look a bit
more cluttered.
@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2022

Codecov Report

Base: 19.24% // Head: 19.22% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (bdb64a2) compared to base (913c9ed).
Patch coverage: 7.40% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #918      +/-   ##
==========================================
- Coverage   19.24%   19.22%   -0.02%     
==========================================
  Files          74       74              
  Lines       14069    14094      +25     
==========================================
+ Hits         2708     2710       +2     
- Misses      11361    11384      +23     
Impacted Files Coverage Δ
src/app/data_harvester/memory/general/heim.rs 0.00% <ø> (ø)
src/canvas/canvas_colours.rs 34.24% <ø> (-0.51%) ⬇️
src/canvas/widgets/cpu_graph.rs 0.00% <0.00%> (ø)
src/canvas/widgets/mem_graph.rs 0.00% <0.00%> (ø)
src/canvas/widgets/network_graph.rs 0.00% <0.00%> (ø)
src/components/data_table/draw.rs 0.00% <0.00%> (ø)
src/lib.rs 6.17% <ø> (ø)
src/widgets/process_table/proc_widget_data.rs 9.79% <0.00%> (-0.07%) ⬇️
src/components/tui_widget/time_chart.rs 48.38% <3.03%> (ø)
src/utils/gen_util.rs 51.11% <14.28%> (-11.58%) ⬇️
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ClementTsang ClementTsang force-pushed the reduce_draw_cpu_usage branch 2 times, most recently from 66ab3b4 to a42dfdd Compare November 28, 2022 23:59
@ClementTsang ClementTsang marked this pull request as ready for review November 29, 2022 00:01
Flamegraphs showed that this area seems to be a bit heavy at times with
some inefficient use of iterators and collection. This change should
hopefully optimize this a bit by reducing some collections or
reallocations.

There can also be some further optimizations with less allocations from
callers.
@ClementTsang ClementTsang changed the title other: reduce the CPU time spent for draws other: slightly reduce the CPU time spent for draws Nov 29, 2022
@ClementTsang ClementTsang merged commit 9c3e60e into master Nov 29, 2022
@ClementTsang ClementTsang deleted the reduce_draw_cpu_usage branch November 29, 2022 08:53
@ClementTsang ClementTsang mentioned this pull request Feb 3, 2024
9 tasks
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

Successfully merging this pull request may close these issues.

2 participants