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
Improve table view performance #40
Conversation
d6f5a66
to
b66b029
Compare
@schickling Any ideas on how to reduce more the reuse time? |
After profiling a little bit more, here we have 2 really expensive lines:
Seems like NSDataDetector is slower than a custom Regex (2x the time)... Maybe we should move to a regex for the URLs? |
@poolqf unfortunately I'm very short on time at the moment but moving to Regex sounds good to me! |
Quick update:
There is no good REGEX way to achieve google.com detection as far as I know (and tried) I think this PR should not be merged until you have time to completely review it. |
Issue found for now:
|
pic.twitter urls fixed. Ready to review @schickling 😉 |
8b811e3
to
188b7a4
Compare
188b7a4
to
c4a1449
Compare
Quick update Been using this refactor in my personal app, and I did not have any issues related to it 🎉 |
LGTM 👍 |
Hey! I just updated to the latest Pod version which includes this, and I'm getting a consistent crash here: mutAttrString.setAttributes(attributes, range: element.range) Which is called asynchronously from I was just wondering if you've seen anything like this. Would you like me to create an issue? I tried to look for the root cause but I can't seem to find exactly why this is happening.
|
Hi @JaviSoto , Seems related with #14 . I've been using the 0.4.0 version in a personal app, without issues. But @byAmmerix complained about it few days ago. It is possibly related with the I'll try to look at it, but let's follow this up in #14. Would you mind to give there a little bit of info about the environment you are using (sdk, ios version..)? Thanks! |
🎩 What? Why?
As pointed out in #27 , when using ActiveLabel inside a cell, the whole customisation process that is behind any change on it, makes the table to drop a lot of frames.
The customisation ActiveLabel is doing on every change is expensive, so the intention is to try to reduce the cost of every change.
Things covered:
Changed towards a tableView Demo
This change may not be the better option as a the example project, so considering changing it back to the current example.. 🤔
Rethought way to extract elements from the label text:
Previously the way ActiveLabel was searching for
ActiveElement
s was by iterating through all the words the label had, and then passing a Regex individually to each one of them to see if they wereActiveElement
s or not.Now the Regex Parser is passing the Regex to the whole text at once. And extracting elements based in specific Regex for each
ActiveType
RegexParser
whose only responsibility is to manage Regex related thingsActiveBuilder
. Taking advantage of the RegexParser createsActiveElement
sChanged Way to Test
Previously, the way ActiveElement was checking things was by checking if an String was satisfying the requirements to be an specific ActiveType. This way of testing has been broken with the refactor, so the new way the tests are working now is by passing a text to an
ActiveLabel
and expect that it to contain X amount of active elements, and check the string and type of it.Perform only necessary things when changing variables
At the moment, each time the user sets a property (overridden & custom) we are executing
updateTextStorage()
. This is expensive, and could be a bottleneck.updateTextStorage()
if possible when changing a propRegex is now detecting
#
and@
in the middle of wordsThat should not occur ⛔
#
and@
in the middle of words ( Closes Usernames with periods are not fully highlighted #9 )Move
urlDetector
to use regex:I've been looking for a correct URL Regex, and I've came across with this page: https://mathiasbynens.be/demo/url-regex. The option I've chosen is the one purposed by @krijnhoetmer, and I've tweaked it a bit
urlDetector
google.com
.Maintaining support for old school
www.google.com
📈 DATA
This table reflects the necessary time to customise a cell changing text and textAlignment when calling
cellForRow
:In some cases 10x less time 😱
😮 IMPORTANT:
Even that this PR reduces the label reuse cost, it is not completely solving the issue
👻 GIF