question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Some performance optimization for app and ioc

See original GitHub issue

Hi ,hikalkan
When use Abp,Zero,Abp.zero in project ,when i release to server i found every ajax called app service ,response time is more than 120ms, most of them is more than 150ms. So i write a blank method only return true ,no db search,no other operating,and also respone 120ms. In source i found ,ApplicationServiceBase is inject TenantManager and UserManager. In TenantManager

        public TenantManager(
            IRepository<Tenant> tenantRepository,
            IRepository<TenantFeatureSetting> tenantFeatureRepository,
            EditionManager editionManager,
            IUnitOfWorkManager unitOfWorkManager,
            RoleManager roleManager,
            IUserEmailer userEmailer,
            TenantDemoDataBuilder demoDataBuilder,
            UserManager userManager,
            INotificationSubscriptionManager notificationSubscriptionManager,
            IAppNotifier appNotifier,
            IYueZeroFeatureValueStore featureValueStore
            IYueZeroDbMigrator yueZeroDbMigrator
            )
            : base(
                  tenantRepository,
                  tenantFeatureRepository,
                  editionManager,
                  featureValueStore)
        {
            _unitOfWorkManager = unitOfWorkManager;
            _roleManager = roleManager;
            _userEmailer = userEmailer;
           _demoDataBuilder = demoDataBuilder;
            _userManager = userManager;
            _notificationSubscriptionManager = notificationSubscriptionManager;
            _appNotifier = appNotifier;
            _yueZeroDbMigrator = yueZeroDbMigrator;
        }

Resolve TenantManager will use about 70ms,and the ref classes is only use in CreateWithAdminUserAsync Method,this method is only use in tenant reg but resolve this ref class will cause all appService resolve init use 50ms-70ms

            //_roleManager = roleManager;
            //_userEmailer = userEmailer;
            //_demoDataBuilder = demoDataBuilder;
            //_userManager = userManager;
            //_notificationSubscriptionManager = notificationSubscriptionManager;
            //_appNotifier = appNotifier;
            //_yueZeroDbMigrator = yueZeroDbMigrator;

So i suggested TenantManager change to

        public TenantManager(
            IRepository<Tenant> tenantRepository,
            IRepository<TenantFeatureSetting> tenantFeatureRepository,
            EditionManager editionManager,
            IUnitOfWorkManager unitOfWorkManager,
            //RoleManager roleManager,
            //IUserEmailer userEmailer,
            //TenantDemoDataBuilder demoDataBuilder,
            //UserManager userManager,
            //INotificationSubscriptionManager notificationSubscriptionManager,
            //IAppNotifier appNotifier,
            IYueZeroFeatureValueStore featureValueStore
            //IYueZeroDbMigrator yueZeroDbMigrator
            )
            : base(
                  tenantRepository,
                  tenantFeatureRepository,
                  editionManager,
                  featureValueStore)
        {
            _unitOfWorkManager = unitOfWorkManager;
            //_roleManager = roleManager;
            //_userEmailer = userEmailer;
            //_demoDataBuilder = demoDataBuilder;
            //_userManager = userManager;
            //_notificationSubscriptionManager = notificationSubscriptionManager;
            //_appNotifier = appNotifier;
            //_yueZeroDbMigrator = yueZeroDbMigrator;
        }

        public async Task<Guid> CreateWithAdminUserAsync(string tenancyName, string name, string adminPassword, string adminEmailAddress, string connectionString, bool isActive, Guid? editionId, bool shouldChangePasswordOnNextLogin, bool sendActivationEmail)
        {
            Guid newTenantId;
            Guid newAdminId;

            if (_demoDataBuilder == null) _demoDataBuilder = Yue.Dependency.IocManager.Instance.Resolve<TenantDemoDataBuilder>();
            if (_userManager == null) _userManager = Yue.Dependency.IocManager.Instance.Resolve<UserManager>();
            if (_yueZeroDbMigrator == null) _yueZeroDbMigrator = Yue.Dependency.IocManager.Instance.Resolve<IYueZeroDbMigrator>();
            if (_appNotifier == null) _appNotifier = Yue.Dependency.IocManager.Instance.Resolve<IAppNotifier>();
            if (_notificationSubscriptionManager == null) _notificationSubscriptionManager = Yue.Dependency.IocManager.Instance.Resolve<NotificationSubscriptionManager>();
            if (_roleManager == null) _roleManager = Yue.Dependency.IocManager.Instance.Resolve<RoleManager>();
            if (_userEmailer == null) _userEmailer = Yue.Dependency.IocManager.Instance.Resolve<IUserEmailer>();

and change in ApplicationServiceBase

    public abstract class IWorksApplicationService : ApplicationService
    {
        private TenantManager _TenantManager;
        public TenantManager TenantManager
        {
            get
            {
                if (_TenantManager == null)
                {
                    _TenantManager = Yue.Dependency.IocManager.Instance.Resolve<TenantManager>();
                }
                return _TenantManager;
            }
        }

        private UserManager _UserManager;
        public UserManager UserManager
        {
            get
            {
                if (_UserManager == null)
                {
                    _UserManager = Yue.Dependency.IocManager.Instance.Resolve<UserManager>();
                }
                return _UserManager;
            }
        }

and now every ajax response time is less than 80ms.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Caskiacommented, Jan 11, 2017

I had found the same problem. #1528

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improving Your App's Performance
Performance improvement work is a cycle. Gather data about your app's current performance. Then. Minimizing resource use benefits your users and improves their ......
Read more >
How to Avoid Common App Performance Optimization Pitfalls
Learn how to optimize your app's performance and avoid common challenges and pitfalls with these tips and best practices.
Read more >
How to Optimize Mobile App Performance for Any Scenario
Optimize your app size and resources​​ Another way to optimize your app performance is to reduce your app size and resources. App size...
Read more >
MvvmCross: IoC and ServiceLocation performance
I consider the answer as: There are no any problems with performance when using MvvmCross in usual apps development, however, due to mentioned ......
Read more >
Best practices for app optimization | App quality
Follow these best practices to optimize your app without sacrificing quality. Use Baseline Profiles.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found