-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
perf(buffer)!: filled moves the cell to be filled #1148
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1148 /- ##
=====================================
Coverage 94.2% 94.2%
=====================================
Files 60 60
Lines 14511 14511
=====================================
Hits 13672 13672
Misses 839 839 ☔ View full report in Codecov by Sentry. |
Q: Isn't taking a reference better in terms of performance? (no copy & clone?) |
Depends on the case. Moving is always the simplest solution with the best performance. (= moving the ownership, the data stays exactly the same, nothing needs to be done at runtime with the data, no (64-bit) reference pointer needs to be created). When the data is only read it depends on the size of the data (u16 for example is smaller than a pointer on a 64-bit system → its more efficient to copy then move the u16 instead of using a 64 bit reference. Which is why it's often a performance improvement to
let cell = Cell::new();
Buffer::filled(area, &cell)
drop(cell); // Rust silently does this for everything not moved away at the end of the context In this case we can save the drop and one clone as we can move in the cell directly. This is not very significant on a Cell as a cell is rather small. With stuff like Basically… when the method takes a reference and clones it directly, then it could just take the value directly and allow the caller to decide whether cloning or moving is the better choice. Fun fact: fn something<S: Into<String>>(input: S) { … }
let huge_string: String = …;
something(&huge_string); // into silently clones in this case
drop(huge_string); // Rust silently does this at the end of the context Changing the reference to a move can be a performance improvement (and did for me in the past) which is why I avoid |
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.
Typos: fill -> filled in the change and the commit message / PR
It would be nice to have a succinct rationale added for this to explain why this change makes sense. Not a massive issue as this is not a widely used function.
Probably off-topic to this PR, any idea what the effect of calling Buffer::filled
with a double width string should be / actually is?
Co-authored-by: Josh McKinney <[email protected]>
Likely gibberish, but that's hard to detect as cells with width > 1 are possible and allowed (emojis, …). The ones after the width > 1 cells are skipped I think? It might be an idea to |
Yeah, I think it might be ok, AAAA AA -> A A A . Every second cell is hidden, but will display correctly regardless I think. |
This removes a clone from inside the method allowing the user to do it explicitly when needing.
BREAKING CHANGE:
Buffer::filled
moves the cell instead of taking a reference.#1143 (comment)