I am using the Particle OTA Asset feature set to package binary files to be sent to co-processor as part of my firmware release.
From my testing, it seems that the time it takes to execute the read()
function on the asset is extremely slow after the asset has been read through once.
For example, I have a function which calculates the CRC of the asset, and it executes in about 500 ms the first time I calculate the CRC of the asset.
The second time it takes about 24,000 ms!
Here is the function:
static Logger myLog("app.asset.crc");
uint32_t compute_CRC32(
ApplicationAsset& asset, uint32_t pad_sz, crc32_parameters_t *params
){
myLog.info("Calculating asset CRC of %s", asset.name().c_str());
asset.reset();
myLog.info("Done resetting asset");
uint32_t crc_result = params->initval;
unsigned int loops = 0;
unsigned int total_asset_bytes = asset.size();
unsigned int asset_bytes_remaining = total_asset_bytes;
unsigned int total_bytes = total_asset_bytes + pad_sz;
unsigned int total_bytes_remaining = total_bytes;
bool did_debug = false;
while (asset_bytes_remaining) {
uint8_t buf[2048];
//Determine how many bytes to read from the asset
size_t bytes_to_read = min(asset_bytes_remaining, sizeof(buf));
int read = asset.read((char*) buf, bytes_to_read);
if (read < 0) {
LOG(ERROR, "Error %d reading binary from asset", read);
}
if(!did_debug) {
did_debug = true;
//Print out first few bytes of the asset
myLog.info("First 5 bytes of asset are: %02X %02X %02X %02X %02X",
buf[0], buf[1], buf[2], buf[3], buf[4]
);
}
crc_result = compute_CRC32(
buf, bytes_to_read, 0, loops == 0, params
);
asset_bytes_remaining -= bytes_to_read;
loops++;
if (loops % 10 == 0) {
myLog.info("CRC32 loop %u, progress: %3.1f %%", loops, (float(total_asset_bytes - asset_bytes_remaining)*100)/total_asset_bytes );
}
}
if(pad_sz > 0) {
crc_result = compute_CRC32(
nullptr, 0, pad_sz, loops == 0, params
);
}
return crc_result;
}
And here is the output from the first CRC calculation:
[2025-06-12 14:09:06.358] 0000001678 [app.asset.crc] INFO: Calculating asset CRC of BossApp.bin
[2025-06-12 14:09:06.363] 0000001679 [app.asset.crc] INFO: Done resetting asset
[2025-06-12 14:09:06.375] 0000001690 [app.asset.crc] INFO: First 5 bytes of asset are: B8 58 02 20 59
[2025-06-12 14:09:06.443] 0000001759 [app.asset.crc] INFO: CRC32 loop 10, progress: 12.3 %
[2025-06-12 14:09:06.518] 0000001836 [app.asset.crc] INFO: CRC32 loop 20, progress: 24.6 %
[2025-06-12 14:09:06.593] 0000001908 [app.asset.crc] INFO: CRC32 loop 30, progress: 36.9 %
[2025-06-12 14:09:06.656] 0000001972 [app.asset.crc] INFO: CRC32 loop 40, progress: 49.2 %
[2025-06-12 14:09:06.725] 0000002040 [app.asset.crc] INFO: CRC32 loop 50, progress: 61.4 %
[2025-06-12 14:09:06.781] 0000002095 [app.asset.crc] INFO: CRC32 loop 60, progress: 73.7 %
[2025-06-12 14:09:06.818] 0000002138 [app.asset.crc] INFO: CRC32 loop 70, progress: 86.0 %
[2025-06-12 14:09:06.857] 0000002172 [app.asset.crc] INFO: CRC32 loop 80, progress: 98.3 %
[2025-06-12 14:09:07.007] 0000002322 [app.boss] INFO: BossApp img bytes: 0x28B04 - pad bytes: 0x174FC - total: 0x40000 - crc = 66c9f394
and here is the second calculation:
[2025-06-12 14:09:07.843] 0000003159 [app.asset.crc] INFO: Calculating asset CRC of BossApp.bin
[2025-06-12 14:09:07.843] 0000003160 [app.asset.crc] INFO: Done resetting asset
[2025-06-12 14:09:07.950] 0000003267 [app.asset.crc] INFO: First 5 bytes of asset are: B8 58 02 20 59
[2025-06-12 14:09:09.175] 0000004490 [app.asset.crc] INFO: CRC32 loop 10, progress: 12.3 %
[2025-06-12 14:09:11.515] 0000006831 [app.asset.crc] INFO: CRC32 loop 20, progress: 24.6 %
[2025-06-12 14:09:15.412] 0000010727 [app.asset.crc] INFO: CRC32 loop 30, progress: 36.9 %
[2025-06-12 14:09:18.889] 0000014204 [app.asset.crc] INFO: CRC32 loop 40, progress: 49.2 %
[2025-06-12 14:09:22.366] 0000017682 [app.asset.crc] INFO: CRC32 loop 50, progress: 61.4 %
[2025-06-12 14:09:27.585] 0000021508 [app.asset.crc] INFO: CRC32 loop 60, progress: 73.7 %
[2025-06-12 14:09:31.835] 0000027150 [app.asset.crc] INFO: CRC32 loop 70, progress: 86.0 %
[2025-06-12 14:09:31.906] 0000027227 [app.asset.crc] INFO: CRC32 loop 80, progress: 98.3 %
[2025-06-12 14:09:32.359] 0000027674 [app.dfu] INFO: Done calculating expected CRC of new image: 66C9F394
Why does reading from an asset work so much faster the first time, and so much slower on subsequent readthroughs?