App icon indicating copy to clipboard operation
App copied to clipboard

[Metrics] ManualShutterToConfirmation - Optimize "Confirm details" page rendering after receipt capture

Open Julesssss opened this issue 9 months ago • 117 comments

Target: 400 miliseconds


Problem

After capturing a receipt photo, the transition to the "Confirm details" page adds noticeable latency. Even after improving the image capture pipeline itself, the rendering cost of the confirmation page may still be a bottleneck.

Goal

Profile the "Confirm details" page mount and render cycle to identify optimization opportunities. Reducing render time here would make the shutter-button-to-confirmation transition feel snappier.

Plan:

  • ~~Add sentry tracking spans for the flow~~
  • ~~@Julesssss to build sentry dashboard~~
  • Deep investigation into problematic areas and anywhere we can reduce rendering time and improve app performence on web and mobile platforms

Related

  • #81849 — parent tracking issue for Create Expense flow metrics

Julesssss avatar Feb 25 '26 22:02 Julesssss

Not sure if there is enough data for the manual shutter span, but here's the query filtered to native since that's the only place that it matters. Some of those look kind of wonky so some spans might not be getting canceled.

marcaaron avatar Feb 26 '26 01:02 marcaaron

Hi Jakub from Callstack, I would like to work on this issue.

kubabutkiewicz avatar Feb 26 '26 17:02 kubabutkiewicz

Daily update: I was looking into this today so I can familiarise myself with the code and I am looking where we should add the spans and if we need only one span or more granular spans to be able to track all the parts of this flow.

kubabutkiewicz avatar Feb 26 '26 17:02 kubabutkiewicz

Hi @Julesssss, created a PR for adding spans for this flow. I am using the ManualShutterToConfirmation as parent span added by @marcaaron ManualReceiptCapture Camera capture + image cropping. Starts when the shutter fires, ends when cropImageToAspectRatio() resolves. Measures the time to grab the screenshot/photo from the camera and crop it to the viewfinder aspect ratio. Includes native camera I/O on mobile, canvas operations on web. ManualScanProcessAndNavigate Onyx writes + participant resolution + navigation dispatch. Starts at the top of navigateToConfirmationStep() in useReceiptScan.ts, ends when navigateToConfirmationPage() is called in IOUUtils.ts. This covers handleMoneyRequestStepScanParticipants — writing the receipt to Onyx, resolving the expense policy/report/participants, and dispatching the React Navigation call. ManualConfirmationMount React Navigation transition + component mount. Starts right after navigation is dispatched (in navigateToConfirmationPage), ends in the useEffec of IOURequestStepConfirmation. Measures the time React Navigation takes to complete the screen transition and mount the confirmation component tree. ManualConfirmationListReady Onyx hydration + list render with data. Starts in the confirmation mount useEffect, ends in MoneyRequestConfirmationList when transaction?.transactionID becomes truthy. Measures how long it takes for the useOnyx hooks to hydrate the transaction data and for the confirmation list to render with actual content. ManualConfirmationReceiptLoad Receipt image loading in the footer. Starts in the confirmation mount useEffect, ends when handleReceiptLoad() fires in MoneyRequestConfirmationListFooter (the image's onLoad callback). Measures the time for the receipt thumbnail/image to actually appear on screen.

kubabutkiewicz avatar Feb 27 '26 16:02 kubabutkiewicz

Thanks @kubabutkiewicz, nice breakdown. Once live I'll update Sentry.

Julesssss avatar Feb 27 '26 20:02 Julesssss

Daily update: Not much update from me on this, currently mostly investigating the code there. PR for creating the spans was merged https://github.com/Expensify/App/pull/83729 waiting now to gather some data to agree on the target for this metric

kubabutkiewicz avatar Mar 02 '26 21:03 kubabutkiewicz

Daily update: Exploring several optimizations in the receipt capture -> confirmation flow on native:

  • Thumbnail pre-generation: After cropping, we now generate a small (512px) thumbnail at capture time and store it on the transaction receipt. This avoids decoding the full 12MP camera image when rendering the confirmation page preview.
  • Reduced JPEG quality on crop: Lowered the crop output compression from 1.0 to 0.85 — smaller file, faster I/O, no visible quality loss.
  • Upload directory caching: The receipts upload folder existence check is now cached so it only runs once per app session instead of on every capture.

Initial results are looking promising but need further testing.

kubabutkiewicz avatar Mar 03 '26 22:03 kubabutkiewicz

Hey @kubabutkiewicz! We merged a change that will remove the cropping entirely. And the upload directory caching was also implemented in that same PR. Check it out here.

I'm trying to think of some things to look at next though.

Thumbnail pre-generation

This sounds interesting.

marcaaron avatar Mar 04 '26 01:03 marcaaron

Ah thanks for letting me know @marcaaron !

kubabutkiewicz avatar Mar 04 '26 08:03 kubabutkiewicz

Daily update:

I am investigating the thumbnail pre-generation as it seems to have a potential of nice improvment.

kubabutkiewicz avatar Mar 05 '26 16:03 kubabutkiewicz

@Julesssss could you send the link to the sentry dashboard ?

kubabutkiewicz avatar Mar 05 '26 16:03 kubabutkiewicz

Update: working on pregenerating the thumbnails looks that its improving perf of this flow by ~10%. I am working on the proposal for that and draft pr

kubabutkiewicz avatar Mar 09 '26 18:03 kubabutkiewicz

Also I think we should set the target for this metric. Right now from Vit query it seems that p90 is 1.93s so maybe a fair target for now would be 1s. let me know what do you think @Julesssss

kubabutkiewicz avatar Mar 09 '26 18:03 kubabutkiewicz

Hi @kubabutkiewicz, sorry I missed this on Friday! It sits under the Create Expense dash.

  • [2] Shutter button -> "Confirm details"
  • [2] "Create expense (scan)" to "Confirm details"

Yeah I agree with 1 second, seems very reasonable for this action.

Julesssss avatar Mar 09 '26 19:03 Julesssss

Hey @kubabutkiewicz, any luck with the thumbnails issue?

Julesssss avatar Mar 11 '26 16:03 Julesssss

yeah, I did measurements on emulator and the results seems there is improvments span ManualShutterToConfirmation before 970ms after 871ms ~10% span ManualConfirmationMount before 214ms after 164ms ~23% I am now testing this is physical device found some issues and resloving them now. I will prepare draft PR

kubabutkiewicz avatar Mar 11 '26 17:03 kubabutkiewicz

Created a draft PR https://github.com/Expensify/App/pull/84919 Should i proceed with that or firstly I should create a proposal?

kubabutkiewicz avatar Mar 11 '26 18:03 kubabutkiewicz

Should i proceed with that or firstly I should create a proposal?

Oh please just go ahead with the draft PR, it's a good improvement on paper. How expensive generateThumbnail is? I'm sure you've found it to be quicker than what we currently have but just curious.

Julesssss avatar Mar 11 '26 22:03 Julesssss

Wondering what you guys think of this proposal here. I have a PR that is feeling pretty good, but could use some feedback.

marcaaron avatar Mar 12 '26 00:03 marcaaron

@marcaaron I reviewed your PR and added a comment

kubabutkiewicz avatar Mar 12 '26 09:03 kubabutkiewicz