ContextLabel icon indicating copy to clipboard operation
ContextLabel copied to clipboard

Lags on RTL Languages

Open Mahan3340 opened this issue 6 years ago • 6 comments

Hi , its Lags when the Language is RTL like 'Persian' , even when there's no hashtag/Link/Mention in the text and the longer the texts gets the more its lags (Using it in UITableView) I have to mention that when using normal UILabel with text with more than 50 lines and more than 1000 items in the table just works fine without any lag so there must be something with the lib in RTL languages , I appreciate if you could fix this as all the Libs out there have the same problem and your Lib has the best performance among them till now .

  • using swift 4 Xcode 9
  • Lib version (1.4.0)
  • test on Simulator and iphone 6s and iphone 6s Plus

Mahan3340 avatar Jun 13 '18 08:06 Mahan3340

@Mahan3340 could you please share a sample text I can use for testing that out.

michaelloistl avatar Jun 13 '18 09:06 michaelloistl

در جایگاه سوم باکس‌آفیس این هفته دنباله کمدی موفق «ددپول» قرار گرفته است که توانسته تا با 14 میلیون به کار خود در هفته چهارم پایان دهد. به این ترتیب این اکشن موردانتظار از مرز فروش 280 میلیونی در بازار داخلی گذشت. همچنین «ددپول 2» در بازار جهانی هم 18 میلیون دیگری فروش داشته است تا مجموع فروش آن از مرز 650 میلیون عبور کند و به یکی از موفق‌ترین فیلم‌های سال تبدیل شود. رایان رینولدز در نقش اصلی و جاش برولین در نقش منفی داستان به همراه مورنا باکرین، زیزی بیتز، تی‌جی میلر و برایانا هیلدبرند از جمله ستارگان شناخته‌شده این عنوان می‌باشند. کارگردانی این اکشن ابرقهرمانی هم توسط آقای دیوید لیچ انجام شده است که کارگردانی و تهیه‌کنندگی سری اکشن محبوب «جان ویک» را در کارنامه خود دارد.

و اما دیگر ورودی جدید و موفق این هفته که توانسته است تا خود را در بین عناوین برتر جای دهد، «ارثی»، تریلر تحسین‌شده کمپانی A24 می‌باشد که جدیدا با ریلیز عناوین موفق سروصدایی در بین کمپانی‌های بزرگ به‌پا کرده است. «لیدی برد»، «مهتاب»، «اتاق»، «جادوگر» و بسیاری فیلم جذاب و تحسین‌شده دیگر، از عناوینی هستند که کمپانی نوظهور A24 وظیفه ریلیز آن‌ها را برعهده داشته است. در هر صورت، «ارثی»، جدیدترین عنوان این استودیو محسوب می‌شود که در این هفته موفق شده است تا با فروش 13 میلیونی در جایگاه چهارم جدول قرار بگیرد. این تریلر نیمه ترسناک که در نزدیک به 3 هزار سینما به اکران درآمده است، با همین میزان فروش افتتاحیه رکورددار کمپانی سازنده خود شده است. نمرات فوق‌العاده 8 از 10 کاربران وبسایت IMDb، و 92 از 100 کاربران وبسایت روتن‌تومیتوز و همچنین 87 از 100 منتقدین وبسایت متاکریتیک، از زیبایی و بی‌نقصی این تریلر ترسناک خبر می‌دهند. داستان فیلم از آنجایی شروع می‌شود که بزرگ یک خانواده‌ای از دنیا می‌رود و خانواده دختری وی پس از مرگش، به حقایق ترسناکی در مورد جد مرموز خود دست می‌یابند؛ آن‌ها هرچه بیشتر جلو می‌روند، بیشتر در معرض سرنوشت شیطانی و به ارث‌رسیده خود قرار می‌گیرند. «ارثی» با بودجه کم 10 میلیونی ساخته شده است و به احتمال زیاد با همین روند فروش، به یک موفقیت تازه برای کمپانی سازنده خود تبدیل گردد.

و در نهایت، رتبه پنجم باکس‌آفیس این هفته ما به موفق‌ترین فیلم سال 2018 میلادی، «انتقام جویان: جنگ بی‌نهایت» تعلق میگیرد که به تازگی به باشگاه دو میلیاردی‌های سینما اضافه شده و نام خود را برای همیشه در تاریخ هک کرده است. «جنگ بی‌نهایت» در هفته هفتم اکران خود با افزودن 7 میلیون دلار از بازار داخلی و 10 میلیون دلار از بازار جهانی به فروش کُلی خود، موفق شد تا از مرز 2 میلیارد دلار فروش بگذرد. به این ترتیب پس از «آواتار» محصول سال 2009، «تایتانیک» محصول سال 1997 و «جنگ ستارگان: نیرو برمی‌خیزد» محصول سال 2015، «انتقام جویان: جنگ بی‌نهایت»، چهارمین فیلمی است که توانسته است تا به چنین فروش باورنکردنی دست پیدا کند. این موفقیت نتیجه ده سال زحمت بی‌وقفه استودیو مارول در زمینه فیلمسازی و خلق یک دنیای سینمایی مجزا و جذاب می‌باشد که بسیار مورد احترام و قابل تحسین است. تبریک به همه عوامل و دست‌اندرکاران این استودیو فیلمسازی و همچنین کمپانی دیزنی که به چنین دست‌آورد مهمی رسیده‌اند.

پس از چهارده سال انتظار، دنباله انیمیشن محبوب «شگفت‌انگیزان» از هفته آینده، با همان صداپیشگان و به کارگردانی آقای بِرَد بِرد، برنده دو جایزه اسکار، در بیش از 4200 سینما به روی پرده خواهد رفت. امتیازات فوق‌العاده 97 از 100 از کاربران و منتقدین وبسایت روتن‌تومیتوز، 83 از 100 از منتقدین وبسایت متاکریتیک و 9.3 از 10 از کاربران وبسایت IMDb تا به اینجای کار از بی‌نقص بودن این دنباله به مانند قسمت نخست خبر می‌دهند. محبوبیت بیش از حد قسمت نخست و این وقفه طولانی مُدت، موجب می‌شود که استقبال از این دنباله به احتمال زیاد سورپرایزکننده و فوق‌العاده باشد.

#باکس_آفیس @IranFilm

its persian just copy it :)) this one have # and @ at the end but lags even after removing them ++ also found out that commenting this line textStorage?.setAttributedString(contextLabelData.attributedString) increases performance alot in this case , but losing some functionality like getting the result in onTouch as I guess it's used for caching and so ++ a little feature request : there could be a simple function addRange(from,to,LinkDetectionType) which let us add a range that we know there exist a hashtag or link or .... and we tell the contexLabel that there's a Hashtag there and it doent need to parse all the text . this can help alot . thanks

Mahan3340 avatar Jun 13 '18 16:06 Mahan3340

@Mahan3340 have you tried to use the cache https://github.com/michaelloistl/ContextLabel#use-of-cache ?

michaelloistl avatar Jun 13 '18 18:06 michaelloistl

Oh i’ll try that later but the problem is that even if the text doesnt have any Hashtag or username ,..it lags again , will using cache fix this ? I mean will using cache tell the ContextLabel not to search the whole text and the cache is valid ?

Mahan3340 avatar Jun 13 '18 18:06 Mahan3340

if (dataIndex[indexPath.row].cache == nil) { cell.contentLabel.text = ChatVC.VC.dataIndex[indexPath.row].content dataIndex[indexPath.row].cache = cell.contentLabel.contextLabelData

            }
            else
            {
                cell.contentLabel.contextLabelData = dataIndex[indexPath.row].cache
            }

}

used cache still lagging , I dont get what does this do , even with the caching linkResults function is being called and search all over the text so whats the usage of cache ? shouldn't it just use the results in cache and skip all these pattern matching ? And another problem is that matching is started as soon as the label’s text is set so then its always re doing it in cellForRow in uitableview cause the text should always be set in cellforrow or it will be empty next time , maybe it is better For us to call a function to force label to find matches than being found every time automatically ... and for next times just use the cache if called again and when can not calling it when we know the text is the same as before Something like If haveEverMatched or TextHasChanged { label.findMatchings & set cache}

Else {underline matchings from cache}

Mahan3340 avatar Jun 13 '18 19:06 Mahan3340

@michaelloistl kept testing and debugging for couple of hours and now I'm sure that the lag is caused by textStorage , be removing it didTouch can't find tapped linkResult , if only you could help me how to handle touch without setting attributedText to textStorage the problem is all solved , cause there's no lag when its removed ( + modified code to use cache if linkResults have been found before) so now the only problem is the click

Mahan3340 avatar Jun 14 '18 07:06 Mahan3340