react-native: TextInput becomes slow after writing and clearing
- I have reviewed the documentation
- I have searched existing issues
- I am using the latest React Native version
Environment
OS: Linux 4.16 Node: 8.11.1 Yarn: 1.6.0 npm: 6.0.0 Watchman: Not Found Xcode: N/A Android Studio: 3.1.2 AI-173.4720617
Packages: (wanted => installed) react: 16.3.2 => 16.3.2 react-native: 0.55.3 => 0.55.3
Steps to Reproduce
import React, { Component } from 'react';
import { View, TextInput } from 'react-native';
class App extends Component {
render() {
<View>
<TextInput />
</View>
}
}
- Create a basic app with a single TextInput
- Run the app on Android, with or without debug active, also in production build (signed APK)
- Write in the TextInput anything, delete it and repeat the process until it becomes laggy.
Expected Behavior
TextInput should not start lagging after something has been written inside and deleted.
Actual Behavior
TextInput lags after 40-50 times you delete the input, programmatically or via keyboard, doesn’t really matter also the amount of text inside of it because happens also with a single character.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 28
- Comments: 31 (9 by maintainers)
Commits related to this issue
- Fix extreme TextInput slowness on Android This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a controlled TextInput af... — committed to gnprice/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a controlled TextInput af... — committed to gnprice/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a controlled TextInput af... — committed to svelle/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android Because NaN is special, the `!=` version of this condition will always be true -- even if `mLetterSpacing` is also `Float.NaN`, which is its default value. ... — committed to gnprice/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android Because NaN is special, the `!=` version of this condition will always be true -- even if `mLetterSpacing` is also `Float.NaN`, which is its default value. ... — committed to gnprice/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to facebook/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to macdoum1/react-native by gnprice 6 years ago
- Patch react-native to pick up the fix for https://github.com/facebook/react-native/issues/19126 Patch react-native to pick up the fix for https://github.com/facebook/react-native/issues/19126 from ht... — committed to tidepool-org/mobile by markyou 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to facebook/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android Because NaN is special, the `!=` version of this condition will always be true -- even if `mLetterSpacing` is also `Float.NaN`, which is its default value. ... — committed to springnz/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android Because NaN is special, the `!=` version of this condition will always be true -- even if `mLetterSpacing` is also `Float.NaN`, which is its default value. ... — committed to springnz/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to mdcollab/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android Cherry pick from: https://github.com/facebook/react-native/commit/5017b86 Because NaN is special, the `!=` version of this condition will always be true -- ... — committed to Werkspot/react-native by jackkav 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to Rabbit-Inc/react-native by gnprice 6 years ago
- Fix extreme TextInput slowness on Android (#19645) Summary: This reverts 5898817fc "Implement letterSpacing on Android >= 5.0". Testing shows that that commit is the cause of #19126, where in a contr... — committed to xvonabur/react-native by gnprice 6 years ago
I bisected the changes between v0.54 and v0.55, and found the commit that causes this issue: it’s 5898817fc “Implement letterSpacing on Android >= 5.0”. And indeed reverting that change fixes the issue.
I just sent #19645 with a revert of that change.
The test app I used to repro the issue follows @simone201 's report, with @miguelespinoza 's addition. I
react-native init
Pending #19645 , others who are hitting this issue may be able to fix it by applying that patch to the RN version they use. That’s what I expect to do.
One other inference from identifying the commit that caused it: that commit was intended to have an effect mainly on Android 5.0 Lollipop and up. It’s likely that this issue only happens there. (My testing was on Android 8.1 Oreo.)
Thanks to @simone201 and @miguelespinoza for their detailed descriptions of the issue! These were very helpful in pinning down in the first place the mysterious issue we were seeing in our app, and in the bisection I just did to locate the cause within RN.
@gnprice it appears there was a change request on #19645. We could be nearing the end of this nightmare. Any chance you could address it? I think any company with an app on Android that has a text input (every app ever) would be eternally grateful.
Here’s what I wrote at https://github.com/facebook/react-native/pull/19645#issuecomment-400507673 when I figured out the bug that PR fixed (which was introduced between v0.54 and v0.55 and caused the extreme version of this problem, as described in the original reports in this thread – for short, “bug #19126”):
So this #19126 (i.e., the bug that’s fixed in v0.56 by #19645) was basically a multiplier on the effect of some other, underlying bug. I’ll file an issue for the underlying bug in a moment, so it’ll have a number too.
As far as I know, nobody had previously reported the underlying bug before #19126 made its effects so severe. But now with @s-nel 's detailed observations I think we’re looking at the same underlying bug.
I don’t know anything more about what causes it; even the hypothesis that we’re ending up with large numbers of text shadow nodes is just an inference from how it interacts with the line fixed in #19645. More debugging required. Which I probably won’t do because the remaining symptoms are no longer one of the top issues in our own app, but I hope somebody else will!
@gnprice can this be cherrypicked/backported to 0.55.x? 🙏
0.56 will take another month or so to be released, isn’t it?This is a really terrible bug. As we didn’t know how to fix it (besides from downgrading RN) we switched our inputs to be uncontrolled and that stopped the slowdown. However, on iOS we needed to apply this fix to get the text input to clear in cases such as chat: https://github.com/facebook/react-native/pull/18278.
I’ve filed #20119 with @s-nel 's report and other details from this thread. @shafy @alp1396 @stueynet and anyone else, I recommend we continue the discussion of the still-open issue there. Thanks for all the detailed reports!
After some further debugging today (details on #19645), the fix is reduced to a very simple one! Just this line:
Hopefully that’ll make it into master soon and get cherry-picked into 0.56.
I tried spinning up a fresh
react-native init
project, attempting to isolate the issue.This seems to only be an issue with controlled
TextInput
from what I can tell.Seems like a very fundamental issue as
<TextInput>
is basically unusable because of this. I hope we could at least figure out what the source of the problem is.Oh, I should add – here’s a version of that patch on top of the latest release (v0.55.4): https://github.com/gnprice/react-native/commit/a8c65a686c12cd0b7e9a69ed7f1f21efee4cae84
(The version in my PR is rebased on top of master, which involved resolving a few merge conflicts from unrelated changes.)
Ive checked (my local file - node_modules/react-native…ReactBaseTextShadowNode.java) that changes from many PR (seen above) are already IN RN 0.56. But in fact, the problem for me hasn’t been solved. Tested on 2 different xiaomi and 1 samsung devices. All inputs are going slowdown after delete pressed many times. By the way, app running on device emulator works prefect as well!
@s-nel yeah same here
@gianpaj Looks like it’s slated for a cherry-pick into 0.56: https://github.com/react-native-community/react-native-releases/issues/14#issuecomment-400954904
For 0.55.x, there’s a discussion over here on whether it makes sense for the RN maintainers to publish further releases in that series: https://github.com/react-native-community/react-native-releases/issues/11
@gianpaj the final
0.56
release will be published Monday. You can request a 0.56 cherry pick over at https://github.com/react-native-community/react-native-releases, otherwise this is scheduled to hit the next release, 0.57, which will also be available next week.Based on the GIF I would say it’s an issue with the TextInput JS code. Maybe some heavy calculations that’s blocking the JS thread. I don’t have a chance to dig deeper.
I currently had to downgrade to RN 54. But this is temporary. Right now this is blocking issue. Not sure how we can escalate this