.netasp.net-mvciist4mvc

T4MVC and performance issues


I have been using T4MVC for quite a while now. I have a high traffic site that keeps growing every year and we have noticed some performance issues. We are using LeanSentry and we are seeing these type of CPU spikes with our T4MVC URL generation. Below is one high CPU userage snapshot with these codelines made available.

Is this a valid concern or something else?

enter image description here

Example of performance hit code generating URLS

protected virtual void PopulateScheduleGameLinks(List<ScheduleGroupDisplay<ScheduleGameDisplay>> gamesGroup)
        {
            gamesGroup.SelectMany(q => q.Games)
                .ToList()
                .ForEach(
                    q =>
                    {
                        foreach (var asset in q.Assets)
                        {
                            asset.Url = Helper.GetFilePath(asset.Url, asset.Version);
                        }

                        if (q.ExternalId != null)
                        {
                            long ticks;
                            if (long.TryParse(q.ExternalId, out ticks) &&
                                q.StatisticsType != StatisticsType.MyStatsOnline &&
                                q.StatisticsType != StatisticsType.ScorebookPlus &&
                                q.Assets.All(t => t.Type != GameAssetType.Scoresheet))
                            {
                                q.Assets.Add(new ScheduleGameAssetDisplay
                                {
                                    Type = GameAssetType.Scoresheet,
                                    Url = Url.Action(MVC.EventReports.GameStatistics(q.EventId, null, q.Id.ToString()).AddReportPdf().AddRouteValue(Config.QueryString.Version, ticks))
                                });
                            }
                        }

                        q.LiveGameLink = this.BuildScoreCastUrl(q.StatisticsType, q.ExternalId, null, q.Id, q.EventId, q.SportHost, q.EventName.GenerateSlug());
                        q.CalendarLink = Url.Action(MVC.Calendar.Game(q.Id));
                    });

        }

enter image description here

enter image description here


Solution

  • T4MVC itself is not doing much here beyond calling UrlHelper.RouteUrl, which is part of MVC. So I suspect you would see the same thing if you were to use UrlHelper.RouteUrl directly to generate URLs without using T4MVC.

    It could be that this MVC method is somewhat expensive, and that the perf issue comes as a result of having too many calls to it to render a single page (e.g. if the page is very complex and contains many generated URLs).