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

prototype(FastText): Add option to use TextBlock for simple text #1256

Merged
merged 6 commits into from
Aug 14, 2018

Conversation

rozele
Copy link
Collaborator

@rozele rozele commented Aug 1, 2017

Simple text, i.e., text with only a single raw text node as a child, can be transformed into a TextBlock with a Text property, instead of a RichTextBlock with a Paragraph of Inlines. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", set DebugSettings.IsTextPerformanceVisualizationEnabled to true while debugging your app; it changes optimized text color to green.

Fixes #1252

sayar
sayar previously approved these changes Aug 1, 2017
@codecov-io
Copy link

Codecov Report

Merging #1256 into master will decrease coverage by 0.04%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1256      +/-   ##
==========================================
- Coverage   31.84%   31.79%   -0.05%     
==========================================
  Files         258      259       +1     
  Lines       18674    18703      +29     
  Branches     1580     1584       +4     
==========================================
  Hits         5947     5947              
- Misses      12574    12603      +29     
  Partials      153      153
Impacted Files Coverage Δ
...ctNative.Net46/Views/Text/ReactTextCompoundView.cs 0% <0%> (ø) ⬆️
...ative.Net46/Views/Text/ReactFastTextViewManager.cs 0% <0%> (ø)
...eactNative.Net46/Views/Text/ReactTextShadowNode.cs 0% <0%> (ø) ⬆️
...ows/ReactNative.Shared/UIManager/RootViewHelper.cs 15.55% <0%> (-2.87%) ⬇️
...indows/ReactNative.Net46/Shell/MainReactPackage.cs 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ededb4d...7c30286. Read the comment docs.

sayar
sayar previously approved these changes Aug 4, 2017
return frameworkElement.Parent;
}
#if !WINDOWS_UWP

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename these two variables to just "element" with #if UWP for the different casts, and then deduplicate the if+return?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think you're reading it wrong, we had to add the extra check for WPF because there is a difference between RichTextBlock and TextBlock in WPF.


In reply to: 132557372 [](ancestors = 132557372)

@rozele rozele dismissed sayar’s stale review August 22, 2017 13:44

This is just a prototype.

@@ -263,6 +275,14 @@ const Text = React.createClass({
if (this.context.isInAParentText) {
return <RCTVirtualText {...newProps} />;
} else {
if (Platform.OS === 'windows' && typeof newProps.children === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

this.props.children can be an array of strings and in many cases this array can contain just one string. If such arrays are concatenated with .join("") this fix covers 99% of text in S4L.

Copy link
Contributor

Choose a reason for hiding this comment

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

This was fixed in S4L.

{
return frameworkContentElement.Parent;
}
#endif
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Deferring non FrameworkElement/FrameworkContentElement to VisualTreeHelper.GetParent seems to make total sense, the helper being smart enough to understand the intricacies of various elements, etc.
Well, nope. The call throws System.Exception(E_UNEXPECTED) if passed a correctly parented/in visual tree InlineUIContainer, for example.

ladipro pushed a commit to ladipro/react-native-windows that referenced this pull request May 16, 2018
This is Eric Rozell's [PR](microsoft#1256) with a couple fixes to make it work with S4L. This optimization [gives](aka.ms/V3mz2) a 10% speedup and reduces memory usage by 10%.

Simple text, i.e., text with only a single raw text node as a child, can be transformed into a TextBlock with a Text property, instead of a RichTextBlock with a Paragraph of Inlines. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", set DebugSettings.IsTextPerformanceVisualizationEnabled to true while debugging your app; it changes optimized text color to green.

Related work items: #1164947
@rozele rozele force-pushed the issue1252 branch 2 times, most recently from 9566a3b to 96a49fa Compare May 18, 2018 22:18
if (this.context.isInAParentText) {
return <RCTVirtualText {...newProps} />;
} else {
if (Platform.OS === 'windows' && typeof newProps.children === 'string') {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Platform.OS === 'windows' & [](start = 10, length = 27)

Instead of platform check, use RCTSimpleText or something else.

/// <summary>
/// The shadow node implementation for text views.
/// </summary>
public class ReactSimpleTextShadowNode : LayoutShadowNode
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ReactSimpleTextShadowNode [](start = 17, length = 25)

Revert file name to maintain diff.

@@ -172,6 +172,7 @@
<Compile Include="Views\Scroll\ScrollView.cs" />
<Compile Include="Views\Slider\ReactSliderManager.cs" />
<Compile Include="Views\TextInput\PlaceholderAdorner.cs" />
<Compile Include="Views\Text\ReactSimpleTextViewManager.cs" />
<Compile Include="Views\Text\ReactTextCompoundView.cs" />
Copy link
Contributor

@reseul reseul May 18, 2018

Choose a reason for hiding this comment

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

@rozele Where's the shadow node?

[edit]: Oh, it's a dummy implementation for WPF?

reseul
reseul previously approved these changes May 18, 2018
Copy link
Contributor

@reseul reseul left a comment

Choose a reason for hiding this comment

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

:shipit:

antonkh
antonkh previously approved these changes May 18, 2018
if (this.context.isInAParentText) {
return <RCTVirtualText {...newProps} />;
} else {
if (RCTSimpleText && typeof newProps.children === 'string') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be an array of strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@reseul - not sure if we are supposed to handle the array of strings. I don't know what the concatenation handling should be, whether we just inject a space, newline, etc. Also, I imagine this can vary based on culture/i18n. I'd like to keep this as a single space for now and force the client to specifically concatenate string arrays if they want text perf optimization.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rozele it's ok. We've been using this fast text for some months, but I'm not sure whether we have that case. If we do. we're going to reconcile on our end.

/// <returns>The view instance.</returns>
protected override TextBlock CreateViewInstance(ThemedReactContext reactContext)
{
var richTextBlock = new TextBlock
Copy link
Contributor

Choose a reason for hiding this comment

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

This text block is not exactly rich.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll change to var poorTextBlock :)

rozele added 6 commits August 13, 2018 19:18
Simple text, i.e., text with only a single raw text node as a child, can be transformed into a `TextBlock` with a `Text` property, instead of a `RichTextBlock` with a `Paragraph` of `Inlines`. This change detects in the React Native Text node has a single raw text child, and if so, uses the FastText native component. To test if your text nodes are "fast", set `DebugSettings.IsTextPerformanceVisualizationEnabled` to true while debugging your app; it changes optimized text color to green.

Fixes microsoft#1252
Also taking the latest from Text.js in [email protected].*
@rozele rozele dismissed stale reviews from antonkh and reseul via 51c6bdb August 13, 2018 23:19
@rozele rozele merged commit 7fa57fc into microsoft:master Aug 14, 2018
rozele added a commit that referenced this pull request Aug 14, 2018
rozele added a commit that referenced this pull request Aug 14, 2018
…ext (#1256)" (#1939)

Reverts #1256. We need to update Text.windows.js to be in sync with the latest from react-native first.
reseul pushed a commit to reseul/react-native-windows that referenced this pull request Oct 18, 2018
…simple text (microsoft#1256)" (microsoft#1939)"

This reverts commit adb4539.
Updated for the latest Text.js implementation
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.

8 participants