Profile Neuron calculations

With Neuron, we can evaluate the accuracy and performance of compiled Wasm by using a Debug build.

Prepare the Excel file

  1. With your Excel file, apply the appropriate mappings to identify inputs and outputs.

  2. Add a new named range referenced to a cell called xBuildParams. Set its value to '--build=Debug as shown in the screenshot.

Examine self-test results

  1. Make sure to complete the steps in Prepare the Excel file.

  2. Upload the service to Spark. Note that Debug builds are slower to compile and execute and should only be used for debugging purposes only.

  3. Upon the completion of the upload, the compiler logs will contain detailed information about the Neuron self-test (see Neuron compiler messages). Download the log and inspect the file contents. Look for the trace object.

    • Calculations are listed in the order they are performed.

    • c cell address.

    • v value calculated by Neuron.

    • e expected calculation by Excel using the value saved into the file.

    • match indicates whether or not v = e within the accuracy described in the compiler message.

    • soe and moe are error metrics described in Self-test.

Profile the calculations

  1. Make sure to complete the steps in Prepare the Excel file.

  2. Navigate to the API Tester.

  3. In the Raw view add the additional parameters to the request_meta:

    • "profile": true enables the profiling actions. This records the start and end timestamp for the calculation of each cell.

  4. Optionally in the request_meta you can include "top_n_profile": {number>0}:

    • This returns the calculation time for the {number} of sheets, columns, rows, and cells each respectively.

    • If this parameter is included, then the Perfetto visualization described below cannot be used.

  5. Remember to separate these parameters with a comma (,).

  6. Send the API call a few times to ensure the service is cached in the Spark environment.

  7. The profile results will not be displayed in the API Tester as the contents may be very long and affect the user interface.

  8. Open your browser's Developer Tools Network Inspector (Chromearrow-up-right, Edgearrow-up-right, Firefoxarrow-up-right, Safariarrow-up-right).

  9. Submit an additional API call and identify the call to the Execute endpoint. You can view the response of the API call. Note that the response should include an object for traceEvents. The output depends on whether the optional "top_n_profile": {number} was provided.

    "profile": true
    "profile": true and "top_n_profile": n

    traceEvents follow the Trace Event Formatarrow-up-right.

    This output cannot be used in Perfetto.

  10. Copy the entire response into a text file and save the filename with a .json file extension.

  11. If you skipped the "top_n_profile" parameter, then you can visualize the trace. Go to Perfetto UIarrow-up-right. Select Open trace file and open the saved response.

  12. It will display a trace visualizationarrow-up-right of the calculation time trace for the formulas within a workbook.

    • The bars listed the highest denote the time it takes for formulas that are calculated last. They depend on the calculations from formulas that take place below them.

    • The lowest and longest item indicated in the trace usually indicates an area for improvement. The slower calculation time for these cells prevents the dependent cells above them from being calculated sooner.

Identify the longest calculation chain

Very long calculation chains can consume memory and lead to incomplete calculations. These long calculation chains can be identified using the steps below.

  1. Make sure to complete the steps in Prepare the Excel file.

  2. Upload the service to Spark. Note that Debug builds are slower to compile and execute and should only be used for debugging purposes only.

  3. Navigate to the API Tester.

  4. In the Raw view add the additional parameters to the request_meta:

    • "show_max_calc_chain": true enables logging the longest calculation chain.

  5. There will be 2 additional returned objects:

    • outputs.additional_outputs.max_calc_info notes the longest calculation depth and the location of the cell.

    • outputs.additional_outputs.max_calc_chain indicates the cells that are part of the calculation chain.

  6. To resolve this issue we can use the Xprecalc function that can evaluate long calculation chains in the middle breaking it into smaller chains.

    1. Identify a cell that is midway in the calculation chain.

    2. In an empty part of the workbook create a new Named range called Xprecalc. In this cell, create a formula that references the previously identified cell. For example if the middle of the calculation chain was A123, then set Xprecalc to =COUNT(A123).

    3. If there are still issues, identify more breakpoints for long calculation chains and add them to the Xprecalc. For example, if we also identify B456 as good cell to split the same or another calculation chain, set Xprecalc to =COUNT(A123,B456).

Last updated