sindresorhus/Actions

Slow large-CSV parsing

Closed this issue · 2 comments

Description

Hello,

First of all, many thanks for this app! It is really useful :). Now, into the problem...

I am trying to create a shortcut in order to import data into Apple Health from a CSV file (exported from another application). Initially I was using another shortcut which failed when the file had strings containing commas. Then, I found out Actions, which luckily considers this case :) . The disadvantage, though, is that reading items from a "large" CSV (60kB, 500 lines, 19 columns) takes a really long time (i.e., several seconds per item).

I'm not sure if this is a known-issue (couldn't find anything after a brief search), or a problem on my end, but I don't mind helping debugging/fixing this. I don't think that my Shorcuts workflow does anything weird, I just have (simplifying):

  1. Parse $CSV_FILE
  2. Repeat with each item in Parsed CSV
    2.1 Get value 'date' in Repeat Item
    2.2 Set variable entryDate to Dictionary Value
    2.3 Get value 'measurement' in Repeat Item
    2.4 Set variable entryValue to Dictionary Value
    2.5 Find All Health Samples where Type is 'measurementType' and StartDate is on entryDate
    2.5.1 Check if entry already exists, etc.

The shortcut seems to spend a lot of time on 2 (but not on any 2.x in particular, just the main loop action) . I'm not sure 2.1 and onward are the bottleneck: the workflow is similar to the original (quicker) Shortcut, the amount of already-logged samples does not seem to affect speed (i.e., in 2.5), and the loop executes fast with small CSVs.

A small example csv from another repo, which can be made "large" just by duplicating lines until reaching ~500 lines. The shortcut is fast with the small file, but really slow with the large one.

Thanks in advance and let me know if I can add any further details.

macOS/iOS version

iOS 17.4.1

Shortcut URL

https://www.icloud.com/shortcuts/990851ac256546b6a52002233e265696

Since the slowness is at 2, the problem is not the CSV action. Maybe try without the Boolean action. That's the only other action from the Actions app. If it's still slow then, the problem is not Actions.

Since the slowness is at 2, the problem is not the CSV action. Maybe try without the Boolean action. That's the only other action from the Actions app.

Yes, after submitting the issue I actually tried that (i.e., creating texts with either True or False and setting them to a variable) but it was still slow.

If it's still slow then, the problem is not Actions.

After further testing, I think that the problem comes from repeating over the gigantic list-of-dicts from the ParseCSV Action. I'll do some index-slicing and repeat over shorter-sized lists.

Thanks once again!