Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@gaaclarke
Copy link
Member

…and copies)

While investigating flutter/flutter#131620 I tried many things to squeeze the logic to make text batching faster. It didn't pan out but here are a handful of tweaks that make a tiny difference that I don't want to lose.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Comment on lines +200 to 203
for (const Point& point : unit_points) {
vtx.unit_position = point;
::memcpy(contents + vertex_offset, &vtx,
sizeof(VS::PerVertexData));
vertex_offset += sizeof(VS::PerVertexData);
::memcpy(vtx_contents++, &vtx, sizeof(VS::PerVertexData));
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This removes vertex_count add operations.

continue;
}
auto atlas_glyph_bounds = maybe_atlas_glyph_bounds.value();
const Rect& atlas_glyph_bounds = maybe_atlas_glyph_bounds.value();
Copy link
Member Author

Choose a reason for hiding this comment

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

This removes a copy.

@chinmaygarde chinmaygarde changed the title [Impeller] tiny optimizations for text rendering (avoiding extra ops … [Impeller] Tiny optimizations for text rendering (avoiding extra ops and copies). Aug 21, 2023
@gaaclarke gaaclarke marked this pull request as ready for review August 21, 2023 20:01
@gaaclarke
Copy link
Member Author

@dnfield sorry, I meant to put this into review after CI passed and I lost track of this. It's ready now.

@gaaclarke gaaclarke force-pushed the tiny-text-optimizations branch from 3f3d893 to 65990bb Compare August 21, 2023 22:08
Comment on lines +28 to +29
void TextContents::SetTextFrame(TextFrame&& frame) {
frame_ = std::move(frame);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this better? How is the compiler not just doing this for us? haha

Copy link
Member Author

Choose a reason for hiding this comment

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

It can't do it the way it was previously written since it can't know that the frame isn't used after frame_ is set. That's what rvalues and std::move can provide.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you look in the PR, there is one example where you can see SetTextFrame couldn't move the parameter since it is modified and then send to a different SetTextFrame. So by making it an rvalue the compiler knows its safe to just move it.

for (const TextRun& run : frame_.GetRuns()) {
const Font& font = run.GetFont();
auto rounded_scale = TextFrame::RoundScaledFontSize(
Scalar rounded_scale = TextFrame::RoundScaledFontSize(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually doing anything or just a style preference?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the C++ style guide: https://google.github.io/styleguide/cppguide.html#Type_deduction

Use type deduction only if it makes the code clearer to readers who aren't familiar with the project, or if it makes the code safer. Do not use it merely to avoid the inconvenience of writing an explicit type.

@gaaclarke gaaclarke merged commit 21437d3 into flutter:main Aug 22, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 22, 2023
gaaclarke added a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
…and copies). (flutter#44822)

…and copies)

While investigating flutter/flutter#131620 I
tried many things to squeeze the logic to make text batching faster. It
didn't pan out but here are a handful of tweaks that make a tiny
difference that I don't want to lose.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or Hixie said the PR is test-exempt. See [testing the engine]
for instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants