Skip to content

Nativescript + Angular , "random" UI FREEZE and ANR issues! #4204

Closed

Description

@Dimitrievskislavcho

Did you verify this is a real problem by searching [Stack Overflow]

It is a real problem because i have tested it and few of the users already use the app.
I also have been searching for similar issues for a few days now.

Tell us about the problem

The problem is. The app is smooth for a certain period of time , let's say 5 10 minutes, and then
all of a sudden at a random points in time (maybe after selecting an article and a popup dialog opens)
it freezes for a second and then it continues. Few times i had problems when navigating (after navigation) it freezes for a few seconds and it continues (sometimes i get the native not responding dialog). I have seen this issues on 3 or more devices(not that they were top notch units of hardware).

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.5.4
  • Cross-platform modules: 3.0.0
  • Runtime(s): 3.0.0 (tns-android)
  • Plugin(s): (all the deps):
    "dependencies": {
    "angular/animations": "~4.1.0",
    "angular/common": "~4.1.0",
    "angular/compiler": "~4.1.0",
    "angular/core": "~4.1.0",
    "angular/forms": "~4.1.0",
    "angular/http": "~4.1.0",
    "angular/platform-browser": "~4.1.0",
    "angular/router": "~4.1.0",
    "nativescript-angular": "~3.0.0",
    "nativescript-cardview": "^2.0.0-rc.0",
    "nativescript-checkbox": "^1.2.8",
    "nativescript-floatingactionbutton": "^3.0.0",
    "nativescript-ngx-fonticon": "^2.2.0",
    "nativescript-ripple": "^1.1.0",
    "nativescript-snackbar": "^1.1.6",
    "nativescript-telerik-ui": "^2.0.1",
    "nativescript-theme-core": "~1.0.2",
    "reflect-metadata": "~0.1.8",
    "rxjs": "~5.3.0",
    "tns-core-modules": "~3.0.0"
    }

Please tell us how to recreate the issue in as much detail as possible.

For now i would be glad if you can just pin point what might be the problem (where should i seek the answer).
I know about the gc() and --expose_gc flag in package.json. And i did upgrade from 2.5.x to 3.0.0 because i thought that would be a good idea.
p.s. i would love to know how can i profile the app (check device resources ram cpu load ...etc.)
p.s.2 i am new to the android world so bare with me :)

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Not at the moment , but if i struggle some more with this i can provide u with debug version so u can run it ...

Activity

  1. NickIliev commented on May 16, 2017

    @NickIliev
    Contributor

    @Dimitrievskislavcho indeed providing us with a sample application to work with would be great!
    There might be multiple reasons for this to happen (heavy-load API calls, GC calls on navigations, etc.) so working with a sample application to investigate this further is a must.

    When providing the sample code you can also specify on what devices/emulators you are using for testing.

  2. NickIliev commented on May 16, 2017

    @NickIliev
    Contributor

    @Dimitrievskislavcho FYI we have currently dedicated some resources to this task which is related to tracking performance improvements so you can track this thread for tracking techniques.

  3. Cayan commented on May 17, 2017

    @Cayan
    Contributor

    I'm having these issue as well, I've profiled the app using Debug Inspector and it seems like nothing is going on. I've noticed these in two different scenarios:

    • Changing pages
    • ListView's scroll + TabView changing
  4. Dimitrievskislavcho commented on May 17, 2017

    @Dimitrievskislavcho
    Author

    @NickIliev Thanks for giving me directions mate. I had something else the past two days and that is why i didn't have time for some profiling and perf testing. I'll check the link you've provided for me.

  5. Dimitrievskislavcho commented on May 22, 2017

    @Dimitrievskislavcho
    Author

    Hello there again. @NickIliev i tried to do some profiling today but i guess i failed at doing so. Since i am really new to the android dev or android at all i don't really know how and with what tools i should do the profiling. I tried using android monitor but i am guessing there is no GUI for real time profiling (or it's just me and i have no idea what am i doing). The thing is i want to lose my time pinpointing the problems i have not yours :). I want to know how to do profiling and see cpu, gpu and mem usage while i run my app and while i go through my working flow with the app. The problem persists when i click on the groups and some rendering is needed like in ng-repeat with nested angular components and so. And of course the good ol' navigation go to page and destroy this one scenario.
    p.s. sorry about the long text.
    p.s.2 if you can reopen this issue i would gladly post here so other people can relate to my problem.
    p.s.3 i had the crash not responding message after few minutes of work again.

  6. Dimitrievskislavcho commented on May 25, 2017

    @Dimitrievskislavcho
    Author

    @NickIliev @Cayan Hello guys. The noob that i am, i finally got how to do some proper profiling while running the app :). The screenshot is after this boring text i will write.

    -> the ui was blocked for like 10 seconds, as you can see on this SS(it happens on couple of different occasions -> i will describe these after the screenshot).
    -> the page has router outlet with 2 navigation routes, one is a bit heavier of the other, it has levels of selectable items (for in for, items of items [ [item1, item,2] [item3 item4] [item5 item 6] ]). So for example when you click item 4 it updates the main array of items and if it is a leaf item that holds articles it sets the articles and shows the listView with articles (which is a repeat of article component)
    -> the blockage on this page happens either on navigation from this router-outlet subpage to the other that is a bit simpler than this one or it happens when i play with these items and select different item on different level so it can show articles. Sometimes the ui blocks when i select an article of the list and a dialog opens (simple dialog).

    the articles page (the 'heavier subpage') -> item-group and article are the components

    <GridLayout rows="*" class="page">
        <GridLayout row="0" rows="auto, *, auto">
            <CardView row="0">
                <StackLayout orientation="vertical">
    
                    <item-group [hideItemGroup]="groupLevel && groupLevel.length === 1 && i === 0" 
                                (groupSelected)="calculateLevelsArray($event)" 
                                [groupLevel]="groupLevel" 
                                [index]="i" 
                                *ngFor="let groupLevel of levelsArray; let i = index">
                    </item-group>
    
                </StackLayout>
            </CardView>
            <GridLayout row="1">
                <ScrollView id="test" orientation="vertical" [visibility]="!hideList ? 'visible' : 'collapsed'">
                    <ListView [items]="articles">
    
                        <ng-template let-item="item" let-i="index">
                            <StackLayout>
                                
                                <article [type]="'storage_article'"
                                 (showFabButtonEvent)="toggleFab($event)" 
                                 (openPreviewModal)="previewNewOrder($event)" 
                                 [article]="item">
                                 </article>
                                 
                            </StackLayout>
                        </ng-template>
    
                    </ListView>
                </ScrollView>
            </GridLayout>
        </GridLayout>
        <FAB (tap)="goToNewOrderPage()"
            visibility="{{ showFab ? 'visible' : 'collapsed' }}"
            [ngClass]="{'hide_fab': true }"
            hideOnSwipeOfView="test"
            row="1"
            icon="res://add_white"
            rippleColor="#f1f1f1"
            class="fab-button bg-danger">
        </FAB>
    </GridLayout>
    

    the item-group component:

     <GridLayout [visibility]="!hideItemGroup ? 'visible' : 'collapsed'">
                <ScrollView orientation="horizontal">
                    <StackLayout orientation="horizontal">
                        <Button class="btn btn-rounded-lg" [ngClass]="{'btn-primary': selectedIndex === i}" (tap)="selectGroup(group, i)" *ngFor="let group of groupLevel; let i = index" [text]="'    ' + group.GR_OPIS + '    '"></Button>
                    </StackLayout>
                </ScrollView>
            </GridLayout>
    

    the article component is large but i have to link since i reuse it in other pages ():

      <GridLayout columns="auto,*,auto" rows="auto, auto" [ngSwitch]="type">
                    <StackLayout col="0" row="0" verticalAlignment="center" class="page" (tap)="emptyTap=1">
                        <Label class="fa text-muted fa-image-zoom m-l-10 text-center" [text]="'fa-picture-o' | fonticon"></Label>
                    </StackLayout>
                    <StackLayout col="1" row="0" (tap)="checkType() && selectArticle()" class="page" verticalAlignment="center">
                        <Label class="h4 text-primary font-weight-bold p-l-10 p-t-5" [text]="article.code"></Label>
                        <Label class="h5 p-l-10 p-t-5" [text]="article.description"></Label>
                        <Label class="h6 text-danger p-l-10 p-t-5 font-weight-bold" [text]="modifyArticlePrice(article.price)"></Label>
                    </StackLayout>
                    
                    <GridLayout *ngSwitchCase="'storage_article'" height="90" width="90" row="0" col="2" (tap)="toggleFav()" class="page">
                        <Label verticalAlignment="center" horizontalAlignment="center" class="fa fa-x-2 text-primary" [text]="isFavourite() | fonticon"></Label>
                    </GridLayout>
    
                    <GridLayout verticalAlignment='center' *ngSwitchCase="'order_article'" col="2" row="0" columns="auto, auto" rows="auto" class="page">
                        
                        <StackLayout row="0" col="0" verticalAlignment="center">
                            <GridLayout row="0" col="0" columns="auto, auto, auto" verticalAlignment="center">
                                <Button col="0" (tap)="lowerQ()" class="fa btn btn-primary btn-custom-props btn-medium" [text]="'fa-minus' | fonticon"></Button>
                                <TextField col="1" textAlign="center" width="80" keyboardType="number" [(ngModel)]="article.quantity"></TextField>
                                <!--<Button col="1" class="fa btn-custom-props btn-medium btn-quantity" [text]="article.quantity"></Button>-->
                                <Button col="2" (tap)="raiseQ()" class="fa btn btn-primary btn-custom-props btn-medium" [text]="'fa-plus' | fonticon"></Button>
                            </GridLayout>
                        </StackLayout>
    
                        <StackLayout row="0" col="1" verticalAlignment="center">
                            <Button verticalAlignment="center" (tap)="emitRemoveEvent()" horizontalAlignment="center" class="fa fa-x-2 bg-danger m-x-10 btn-medium" [text]="'fa-trash' | fonticon"></Button>
                        </StackLayout>
    
                    </GridLayout>
    
                    <GridLayout verticalAlignment='center' *ngSwitchCase="'in_order_article'" col="2" row="0" columns="auto, auto" rows="auto" class="page">
                        <GridLayout verticalAlignment="center" horizontalAlignment="center" row="0" col="0" columns="auto, *" width="67">
                            <Label col="0" verticalAlignment="center" margin="5" class="fa text-center" [text]="'fa-times' | fonticon"></Label>
                            <Label col="1" horizontalAlignment="left" class="m-r-10 h3 text-center text-primary" [text]="article.quantity"></Label>
                        </GridLayout>
                        <StackLayout row="0" col="1">
                            <Button class="btn btn-primary" [isEnabled]="false" [text]="article.orderNumber"></Button>
                        </StackLayout>
                    </GridLayout>
    
                    <GridLayout horizontalAlignment="left" *ngIf="showExtras()" row="1" col="1" rows="auto, auto" class="m-x-5 m-y-5">
                        <StackLayout row="0" orientation="horizontal">
                            <Ripple horizontalAlignment="left" verticalAlignment="center">
                                <Label verticalAlignment="center" class="fa text-left fa-x-2 text-center" width="30" height="30" [text]="extrasToggledOn ? 'fa-caret-left' : 'fa-caret-down' | fonticon"></Label>
                            </Ripple>
                            <Label text="Додатоци" class="m-x-10"></Label>
                        </StackLayout>
                        <ScrollView orientation="vertical" row="1">
                            <WrapLayout orientation="horizontal" width="210">
                                <Label *ngFor="let extraArticle of article.extras" [isEnabled]="false" class="m-x-5 p-x-5" [text]="extraArticle.extraDescription"></Label>
                            </WrapLayout>
                        </ScrollView>
                    </GridLayout>
                </GridLayout>`
    

    so this was the huge text and i apologize for that but i had to link the markup (i will link the code that executes when clicking if needed);

    And here is the screenshot of the profiling (you can notice where the app stopped and the ui blocked):

    screenshot_1

  7. Dimitrievskislavcho commented on May 25, 2017

    @Dimitrievskislavcho
    Author

    i have tried the app on couple of different devices:

    1. Xiaomi mi4 LTE (had the problem)
    2. Huawei p9 lite (had the problem)
    3. nexus 7 (2013 version) (had the problem)
    4. Tesla tablet L7.1 3G model (had the problem -> the worst performance on this one)
    5. Samsun galaxy s7 edge (didn't see the problem on this one -> short period of testing)
  8. Cayan commented on May 25, 2017

    @Cayan
    Contributor

    @Dimitrievskislavcho what did you use to profile?
    I'm using developer tools and it's not as detailed as the one you provided.

    I'll try to post some screenshots of mine later today.

  9. Dimitrievskislavcho commented on May 25, 2017

    @Dimitrievskislavcho
    Author

    @Cayan i used the Android Monitor in Android Studio ...
    the Monitors tab shows the mem, cpu, network and gpu stats over time.
    First select the device/emulator and the app. Then you will be able to see the graphs.
    If you struggle to find just see the Android Studio docs. There is a detailed info on how to setup so
    you can do the profiling like i did.

    note: if you cannot find the tools > android > android device monitor option in android studio,
    try to map a shell android app (there are templates i think) and then you will see that option.
    I didn't even use any code inside android studio, just the standalone android monitor option.
    Cheers and i hope you will be able to do some proper profiling and finally we diagnose this weird problem.

  10. Dimitrievskislavcho commented on May 26, 2017

    @Dimitrievskislavcho
    Author

    I've been contemplating and i thought of something that might be a reason. (i don't say it must be the reason :)). Angular's change detection. I use the Default strategy and that might be the problem looking from the perspective of how many detector calls are there from time to time. I will try to research some more and i will write if i manage to find something.

  11. Cayan commented on May 26, 2017

    @Cayan
    Contributor

    using OnPush improved the performance a lot for me

  12. 34 remaining items

  13. carrbrpoa commented on Mar 22, 2018

    @carrbrpoa

    Hey @NickIliev, would be nice to see some user feedback (like UI loading, etc.) implemented in the sample project you mentioned. I installed it in my Galaxy S5 NEO and sometimes I touch an option and nothing happens - me, as a user, don't know if something is loading or not - but in some cases the action is fired some seconds after.

  14. william-levi commented on Jun 23, 2018

    @william-levi

    hi ! my app is also lagging for about 1-2 seconds..
    but when it lags there is a message in console
    Can anyone expalin me this console message..

    ActivityManager: getContentProviderImpl: from caller=android.app.ApplicationThreadProxy@fabfd2f (pid=6121, userId=0) to get content provider settings cpr=ContentProviderRecord{62cae88 u0 com.android.providers.settings/.SettingsProvider} 06-23 23:28:24.198 6121 6121 D ActivityThread: holder:android.app.IActivityManager$ContentProviderHolder@dd49ae9, holder.provider:android.content.ContentProviderProxy@3ef236e

    Thanks in advance guys ! Nativescript is awesome

  15. changed the title [-]Nativescript + Angular 2 , "random" UI FREEZE and ANR issues![/-] [+]Nativescript + Angular , "random" UI FREEZE and ANR issues![/+] on Jul 2, 2018
  16. NickIliev commented on Dec 11, 2018

    @NickIliev
    Contributor

    Closing this one as the general issue does not happen on our test apps with the latest modules and Angular. If anyone is still experiencing freeze issue please ping me so we could investigate the case and reopen this one if needed.

  17. devlfm commented on Jan 10, 2019

    @devlfm

    Hi all,

    We are developing a big app with nativescript + angular, and the freezes are completely random.. sometimes opening modals, other times navigating or simply opening the drawer.. it's really disappointing because we wanted to use the same angular codebase for mobile/web apps, and we were very excited when we started last year developing with nativescript, but now we are not so sure if we made the right call :\ pls put more effort and don't give up on this issue..
    I don't have the knowledge to fix or even understand the guts, but it feels to me that the livecycle gets broken/pending.. like the bridge between javascript & java gets blocked or something.. but its just a guess..

  18. NickIliev commented on Jan 11, 2019

    @NickIliev
    Contributor

    @devlfm there is an experimental functionality which can greatly improve the described scenarios. The flag is called markingMode. Details on the feature can be found in this article. and in this PR

    To disable the markingMode in your NativeScript application open the app/package.json (notice that this is not the root package.json but the one located inside the app folder) and add the following key:

    {
      "android": {
        "markingMode": "none"
      }
    }

    Here is an example of how I am using the markingMode in this application (I am not experiencing any freezes or ANR)

  19. devlfm commented on Jan 11, 2019

    @devlfm

    @NickIliev Thank you very much for pointing me out this! great reading.

    I've been trying this flag, and truly stops the freezes! but at a cost of sometimes the app closes for no reason :(

    Is there something I can avoid on code to prevent it? Or something I can use to detect GC errors?

    This should be TOP priority for nativescript team! This flag should be by default on angular projects, as long as there are no issues with GC.

    If you need something from me, just ask!

  20. jeffswitzer commented on Jan 11, 2019

    @jeffswitzer

    Can second devlfm's comment. Turned marking mode on probably a year ago in a project and freezes were fixed, but the app then crashes quite frequently on android. Over the months I've been working on other projects hoping that the marking mode flag becomes more stable. I believe the following stack trace represents what commonly shows during a crash:

    An uncaught Exception occurred on "main" thread.
    com.tns.NativeScriptException: No weak reference found. Attempt to use cleared object reference id=26391
    at com.tns.Runtime.getJavaObjectByID(Runtime.java:892)
    at com.tns.Runtime.callJSMethodNative(Native Method)
    at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1088)
    at com.tns.Runtime.callJSMethodImpl(Runtime.java:970)
    at com.tns.Runtime.callJSMethod(Runtime.java:957)
    at com.tns.Runtime.callJSMethod(Runtime.java:941)
    at com.tns.Runtime.callJSMethod(Runtime.java:933)
    at com.tns.gen.android.app.DialogFragment_frnal_ts_helpers_l58_c38__DialogFragmentImpl.onCreateView(DialogFragment_frnal_ts_helpers_l58_c38__DialogFragmentImpl.java:20)
    at android.app.Fragment.performCreateView(Fragment.java:2353)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
    at android.app.BackStackRecord.run(BackStackRecord.java:816)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1580)
    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6196)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
    
  21. NickIliev commented on Jan 14, 2019

    @NickIliev
    Contributor

    @jeffswitzer @devlfm more on why the above error is happening here and also in this thread. The plugin's team has recently updated all NativeScript's owned plugin to be fully compatible with the experimental feature markingMode but if your app uses other JS references to native Java objects, you will still need to preserve these references in the global object to prevent the GC from collecting them.

  22. jeffswitzer commented on Jan 14, 2019

    @jeffswitzer

    @NickIliev that is really great news about shoring up marking mode compatibility! I haven't tried 5.1 yet but will give it a shot and in the case that some plugins still give me fits will look towards the forthcoming documentation mentioned in the NS 5.1 release notes:

    Next, we are going to focus on producing content and guiding the community on what is needed in order to make all the other plugins compatible as well. More information on this will follow up soon.

  23. devlfm commented on Jan 15, 2019

    @devlfm

    Hi @NickIliev , We are developing a photo/collage editor, and we use indeed some Glide implementations to handle image crop while drawing:

    @Interfaces([ com.bumptech.glide.load.Transformation ])
    class CropTransform extends java.lang.Object {
    
    constructor(private src: string, private croppable: Croppable) {
        super();
        return global.__native(this);
      }
    

    And I'm wondering if return global.__native(this); on ctor isn't already locking this instance of beeing GC?

    I'll checkout what was done on plugins to see if I get it right.

    Thank you

  24. ppyoosuf commented on Mar 13, 2019

    @ppyoosuf

    i am having these issues as well. i tried the markingMode:"none",but it does not giving the good result .any idea to fix this one

  25. lock commented on Mar 12, 2020

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  26. locked and limited conversation to collaborators on Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions