MSBA-270 · Lesson 6 of 12 · 19 min

Designing for performance

▶ Video coming soon A video version of this lesson is on the way.

Two weeks into the pilot of the transcript fee plug-in, Maribeth reported that saving a transcript request had become slow. Advisers were waiting three or four seconds after pressing Save, where before it had been under one. Nobody had changed the plug-in. Signe opened the plug-in trace log and found the cause in a minute: a second developer in the registrar's team had added a step on the same table that retrieved the student's full contact record, all columns, and then the student's last fifty requests, to decide whether to show a loyalty message. Each save now made two large queries that returned hundreds of columns nobody used. Performance problems in Power Platform are rarely about the platform being slow. They are almost always about design.

Where time goes

A request in Power Platform passes through several layers, and each adds time: the network between the user and the service, the app's own work in the browser, the Dataverse API, every synchronous plug-in step and the database queries they make. In a model-driven form, scripts and controls that load when the form opens add to the time before the user can work. In a canvas or code app, the number and size of calls to data sources matter most. A developer designing for performance asks, for each operation, how many requests it makes, how much data each returns and how long the user waits.

A horizontal bar showing the time for one save broken into segments: network, form scripts, Dataverse API, synchronous plug-in step 1, plug-in query with all columns (the longest segment), synchronous plug-in step 2, and database write. A second, shorter bar below shows the same save after fixes, with the plug-in query segment much smaller and step 2 moved to asynchronous.
Where time went in a slow save, before and after the fixes. Times are illustrative.

Efficient queries

The first rule is to ask only for what is needed. In the SDK, a ColumnSet lists the columns to return; requesting all columns returns every column on the table, which can be hundreds, and is one of the most common performance mistakes. The Web API's select option does the same job. Queries should also filter on the server, sort on indexed columns where possible and use paging for large results, rather than retrieving everything and filtering in code. Retrieving rows one at a time inside a loop is another common mistake; a single query that returns all needed rows, or a join through link-entities, is far faster.

Asking for fewer columns and fewer rows. Table and column names are examples.
// Slow: all columns, then filter in code
var all = service.RetrieveMultiple(new QueryExpression("lcc_transcriptrequest") { ColumnSet = new ColumnSet(true) });

// Better: only the needed columns, filtered and limited on the server
var query = new QueryExpression("lcc_transcriptrequest")
{
    ColumnSet = new ColumnSet("lcc_requestnumber", "createdon"),
    TopCount = 5
};
query.Criteria.AddCondition("lcc_student", ConditionOperator.Equal, studentId);
query.Criteria.AddCondition("createdon", ConditionOperator.LastXMonths, 12);
query.AddOrder("createdon", OrderType.Descending);
var recent = service.RetrieveMultiple(query);

Plug-in performance

Synchronous plug-ins add directly to the user's wait, so they deserve the most care. The guidance Microsoft publishes for plug-ins comes down to a short list. Register steps with filtering attributes so they run only when relevant columns change. Use images instead of extra retrieves. Keep synchronous work small and move anything that can wait, such as calling external services or recalculating summaries, to asynchronous steps or to flows. Avoid calling external web services from synchronous plug-ins at all where possible, because the user's save then depends on another system's response time, and any operation must finish within two minutes. Do not keep state in static fields between executions, because plug-in instances are cached and reused, and the platform may run many executions in parallel; a plug-in class should be stateless.

Plug-in performance practices.
PracticeWhy it helps
Filter Update steps on specific columnsThe step runs far less often
Use pre- and post-imagesAvoids extra Retrieve calls
Return only needed columnsLess data from the database and over the wire
Move slow work to asynchronous steps or flowsThe user does not wait for it
Avoid external calls in synchronous stepsThe save does not depend on another system
Keep plug-in classes statelessSafe with caching and parallel execution
Trace sparingly and meaningfullyTrace logs help diagnosis without adding noise

The loyalty message plug-in broke four of these rules. Signe and the registrar's developer rewrote it: the step was filtered to the student lookup column, the student query asked for two columns, the count of previous requests became a rollup column that Dataverse maintained, and the message itself moved to the form as a notification set by a short client script reading the rollup. The save returned to under a second.

Bulk operations and batching

Integrations that write many rows should not send one request per row. Dataverse offers several ways to combine work. ExecuteMultiple sends up to 1,000 requests in one call, each still processed separately. ExecuteTransactionRequest runs a set of requests in a single transaction, all or nothing. The newer bulk operation messages, CreateMultiple, UpdateMultiple, UpsertMultiple and DeleteMultiple, process many rows of the same table in one operation and give the best throughput, especially for elastic tables. Plug-ins can be registered on these bulk messages too, which matters because a plug-in written only for single Create or Update may need attention when integrations switch to bulk messages.

Batching interacts with the service protection limits from lesson 2. Large batches reduce the number of requests but increase execution time per request, so they can hit the execution-time limit instead. Microsoft's guidance is to start with small batches, around ten operations, increase gradually and let Retry-After set the pace. Parallel requests from several threads raise throughput up to the concurrency limit; beyond it, requests are throttled.

Writing a batch of rows to an elastic table in one operation.
// Creating many alarm rows with CreateMultiple (simplified)
var targets = new EntityCollection { EntityName = "lcc_alarmevent" };
foreach (var alarm in batch)
{
    var row = new Entity("lcc_alarmevent");
    row["lcc_assetcode"] = alarm.AssetCode;
    row["lcc_severity"] = new OptionSetValue(alarm.Severity);
    row["lcc_raisedon"] = alarm.RaisedOn;
    targets.Entities.Add(row);
}
var response = (CreateMultipleResponse)service.Execute(new CreateMultipleRequest { Targets = targets });

Model-driven form performance

Forms slow down as they grow. Each tab, section, subgrid, quick view form and control adds work when the form opens. Microsoft's form guidance recommends putting the most-used fields on the first tab, collapsing or delaying tabs that hold subgrids, limiting the number of controls and subgrids, and loading client scripts efficiently. Scripts should not make synchronous network calls, which freeze the browser; the Client API's asynchronous methods and the Web API from client script return promises instead. Form OnLoad handlers should do as little as possible, and expensive work can wait until a tab is opened. Solution checker flags many of these problems automatically, and Monitor shows what the form loads and how long each step takes.

Canvas and code app performance

Canvas apps benefit from the habits covered in MSBA-251: delegable queries, named formulas instead of large OnStart formulas, Concurrent for parallel loading, lighter screens and caching reference data. Code apps follow normal web performance practice: fetch only what a screen needs, page and cache results, avoid chains of dependent calls and keep the bundle small. In both, Monitor shows each call with its duration and size, which makes the slow ones obvious.

Measuring performance

Signe insisted that performance work start with measurement. The tools are the plug-in trace log, which records trace messages and execution times when tracing is enabled; Monitor for apps; Application Insights, which can receive telemetry from Dataverse, model-driven apps, plug-ins and code apps when the environment is connected; and the Power Platform admin center's analytics reports for API calls and capacity. A baseline taken before a change makes it possible to say whether the change helped.

Worked problem

Estimating the gain from images and filtering

A step on Update of the transcript request ran on every update and retrieved the row again to read two columns. The table gets 2,000 updates a day, of which 300 change the delivery method, the only column the logic needs. How many Retrieve calls a day does the old design make, and how many after adding a filtering attribute and a pre-image?

Show solution
  1. Old design: the step runs on all 2,000 updates and makes one Retrieve each, so 2,000 Retrieve calls a day.
  2. With a filtering attribute on the delivery method, the step runs only on the 300 relevant updates.
  3. With a pre-image holding the two columns, those 300 runs need no Retrieve at all.

Answer: From 2,000 extra Retrieve calls a day to none, and from 2,000 plug-in runs to 300.

Asynchronous work done well

Moving work out of the user's wait is the most effective performance change, but asynchronous work has its own design rules. Asynchronous plug-in steps run through the asynchronous service in order of arrival, so a sudden flood of operations can delay them; they should still be efficient. They may run more than once in rare failure cases, so their logic should be idempotent, producing the same result if repeated. Failed asynchronous jobs appear in the system jobs list and should be watched, either by an administrator or by an alert. Cloud flows triggered by Dataverse are also asynchronous and have their own run history and retry policies.

Caching reference data

Some data is read constantly but changes rarely, such as the list of campuses, the transcript fee rates or the asset types. Reading it on every request is wasteful. In client code and code apps, a simple in-memory cache for the session, refreshed occasionally, removes most of those calls. In canvas apps, named formulas or a collection loaded once serve the same purpose. Plug-ins must be careful: because plug-in instances are reused and may run in parallel, any cache must be thread-safe and should expire, and many teams avoid caching in plug-ins altogether except for very small, rarely changing values. The transcript fee plug-in read the rate table each time, because the table had a few dozen rows and the query was cheap with an index on the lookup columns.

Monitoring in production

Performance work continues after release. The Power Platform admin center provides analytics on API calls, failures and capacity per environment. Dataverse can export telemetry to Application Insights, including plug-in executions, form loads and API requests, when an administrator sets up the data export in the admin center. With that in place, the team can build alerts, such as "average form load time for Facilities Hub over five seconds" or "plug-in failures above ten an hour", and see trends before users complain. Lumenvale connected its production environments to an Application Insights resource in the Canada region during the fall, and Signe built a small dashboard that the CoE reviewed each month.

Production signals worth watching.
SignalSourceExample alert
Plug-in failuresApplication Insights or plug-in trace logMore than ten failures in an hour
Form load timeApplication InsightsFacilities Hub main form over five seconds on average
Throttled requestsAPI responses with 429Integration user throttled more than five times a day
Flow failuresFlow run history and admin analyticsNightly job generation fails or creates nothing

Performance budgets

A performance budget is a target agreed before building, such as "a work order saves in under two seconds" or "the Field Tech job list loads in under three seconds on a phone over the college network". Budgets turn vague complaints about slowness into measurable requirements, and they guide design: a synchronous plug-in that takes 800 milliseconds uses almost half of a two-second budget on its own. Lumenvale's technical design template included budgets for the main user actions, and the integration tests measured them, so a change that pushed a save over budget showed up in the pipeline rather than in the service desk queue.

Performance budgets for the facilities solution.
ActionBudgetMeasured with
Save a work orderUnder 2 secondsIntegration test timing and Application Insights
Open the work order formUnder 3 secondsMonitor and form telemetry
Load the Field Tech job listUnder 3 seconds on a phoneMonitor during UAT
Nightly job generationUnder 5 minutesFlow run history

Budgets also help when saying no. When the registrar asked for the loyalty message to be calculated live on every save, the budget made the trade-off visible: the calculation would have used most of the time allowed for saving, so it became a rollup column instead.

Wiremu asked how the team would know whether a budget was realistic. Signe's answer was to measure the current solution first. The baseline for saving a work order before any new plug-ins was about 700 milliseconds, so a two-second budget left room for the new logic while still feeling quick to dispatchers.

Common mistakes

  • MistakeUsing ColumnSet(true) or no select option.

    InsteadList only the columns the code uses.

  • MistakeCalling an external API from a synchronous plug-in.

    InsteadUse an asynchronous step, a flow or a queue so the save does not wait.

  • MistakeSending one request per row from an integration.

    InsteadUse bulk operation messages or ExecuteMultiple with sensible batch sizes.

  • MistakeGuessing where time goes.

    InsteadMeasure with plug-in traces, Monitor and Application Insights, and keep a baseline.

After the fix, Rupert asked for one rule to be added to the team's code review checklist: every plug-in step in a pull request had to state its filtering attributes, its images and why it was synchronous, if it was. It added a minute to each review and saved hours later.

Summary and key terms

  • Performance problems usually come from design: too many requests, too much data, or slow work done while the user waits.
  • Queries should list only needed columns, filter on the server and page large results.
  • Plug-ins should use filtering attributes and images, keep synchronous work small, avoid external calls and stay stateless.
  • Bulk operation messages and ExecuteMultiple reduce requests; batch sizes should start small and respect Retry-After.
  • Forms, canvas apps and code apps each have their own performance practices; measurement with traces, Monitor and Application Insights comes first.
ColumnSet
The list of columns an SDK query returns.
Paging
Retrieving a large result in pages rather than all at once.
Bulk operation messages
CreateMultiple, UpdateMultiple, UpsertMultiple and DeleteMultiple, which process many rows of one table in a single operation.
ExecuteMultiple
A request that carries up to 1,000 separate requests in one call.
Plug-in trace log
A Dataverse log of trace messages and execution details written by plug-ins when tracing is turned on.

Practice problems

Work each problem on paper first, then reveal the answer to check.

  1. Why should a plug-in class not store data in static fields?

    Show answer

    Instances are cached and reused and may run in parallel, so stored state can leak between executions.

  2. What is the maximum number of requests ExecuteMultiple can carry?

    Show answer

    1,000.

  3. Which tool shows each call a running app makes, with its duration?

    Show answer

    Monitor.

Lesson quiz · 5 questions

Score 60% or more to complete this lesson.

Take the quiz