Forum Discussion

Element115's avatar
Element115
Memorable Member
3 years ago
Solved

Power Query engine performance issue

I had to issue 3 REST API calls (over a corporate fiber link on a Dell workstation with 64GB of RAM, and one of the latest Intel CPUs, with 3 SSDs, etc, so the horsepower should be there):    1_get...
  • AlexisOlson's avatar
    3 years ago

    Without seeing your query code, it's a bit difficult to diagnose for sure, but given the size of the data, I'd recommend buffering the table after loading and before any transformations like pivoting. Scroll down to the Buffering section in this article for some more detail about the Table.Buffer function.

     

    Other posts related to buffering:

    https://community.powerbi.com/t5/Power-Query/How-do-I-use-table-buffer-to-speed-up-a-query-How-do-I-create-M/td-p/1174009

    https://community.powerbi.com/t5/Desktop/Using-Table-Buffer/td-p/1535407

    https://community.powerbi.com/t5/Power-Query/Understanding-why-Table-Buffer-makes-a-difference-in-dependency/td-p/746565

    https://community.powerbi.com/t5/Desktop/How-to-Improve-Query-Reference-performance-for-large-tables/m-p/23901

     

    ImkeF has a nice list of various recommendations for improving query performance.

    https://www.thebiccountant.com/speedperformance-aspects/

  • AlexisOlson's avatar
    AlexisOlson
    3 years ago

    I'd consider anything that can comfortably fit into your RAM to not be a large table.

     

    As far as buffering, I suggest buffering right after the API stuff so that any further transformations don't attempt to trigger API calls again.  You could do this at this step:

    rt_table = Table.Buffer(Table.AddColumn(type_change0, "RT_DATA", each getRTData([handleID], token), type record)),

     

    If this table fits in memory nicely, then any subsequent basic transformations should be pretty fast.

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi AlexisOlson - I am wary of this suggestion because Table.Buffer may not like nested Tables or Binary objects.  I have seen this happen with Dataflows.

    Element115 - it will help to buffer before running the very expensive Table.Pivot function.

  • Anonymous's avatar
    Anonymous
    3 years ago

    I glad it starting to help.  One thing that can slow the performance is the API Throttling Limits.  You should check how many send and receives you can make per second or minute.

     

    There are two other things would try, but this will depend on whether original data and API data must fully updated each time.  

    • try an incremental load using the LastReportTime to avoid reload all records each week.
    • if ID_External and Handle_ID are not unique then try running them in a distinct batch to avoid using the API to call the same data more than once. 
  • AlexisOlson's avatar
    AlexisOlson
    3 years ago

    Buffering loads the table to memory as it exists at that particular step. Deciding when and where to do this is more of an experimental art rather than an exact set of rules to follow, especially without a deep understanding of exactly how the query optimization engine works.

     

    Just because you have some version of the table loaded into memory doesn't mean that there's never a need buffer again after that point. If you do expensive calculations or extensive transformations on a table, sometimes it's worth buffering those intermediate results before doing any further steps so that you have those calculations/transformations stored in a format that can be referenced efficiently.

     

    A rather extreme example is this function I wrote here. As ImkeF points out, after I've done some initial transformations to set up some chunks to loop through, buffering them to memory helps a lot since it's doing nested iterations on those chunks. Only buffering the initial input wouldn't be nearly as fast.

     

    It's possible that buffering both before and after the pivot is the fastest but that's something that needs to be tested in your specific situation. Don't go too crazy with buffers though. Take them out anywhere they don't help.

  • Anonymous's avatar
    Anonymous
    3 years ago

    Element115  - 
    For 1 - it depends, as AlexisOlson says it is experimental.  However there is one firm rule that you should follow.  If you are connecting to foldable datasource like a database, don't buffer until after Query Folding breaks.  Buffering at the very start would break folding and effectively load the entire table to temporary memory.

    For 2 - Firstly, I believe Pivot is the more expensive transformation.  Second, I would want Power Query to full complete all the steps before starting the Pivot transformation.  Hence, my strategy would be to place it before Pivot.  However, testing might show that there is very little impact from using either approach.