itemToExportFormat seems to show n^2 time complexity for serialization of attachments.

22 views
Skip to first unread message

Emiliano Heyns

unread,
Jan 30, 2020, 11:03:52 AM1/30/20
to zotero-dev
I understand that massive exports are somewhat a BBT niche, and the caching I do helps, but it seems like itemToExportFormat shows n^2 time complexity for attachments. I have timed how long itemToExportFormat takes, and for item-only libraries, the time to serialize stays pretty much around 0ms; I understand that serializing item + its attachments will take longer, but I had not expected the time-per-item+attachments to steadily rise. Graphs at https://github.com/retorquere/zotero-better-bibtex/issues/1389#issuecomment-580084253 . The singular peaks are not the problem, but the trend is.

Emiliano Heyns

unread,
Jan 31, 2020, 6:14:27 AM1/31/20
to zotero-dev
On Thursday, January 30, 2020 at 5:03:52 PM UTC+1, Emiliano Heyns wrote:
I understand that massive exports are somewhat a BBT niche, and the caching I do helps, but it seems like itemToExportFormat shows n^2 time complexity for attachments. I have timed how long itemToExportFormat takes, and for item-only libraries, the time to serialize stays pretty much around 0ms; I understand that serializing item + its attachments will take longer, but I had not expected the time-per-item+attachments to steadily rise. Graphs at https://github.com/retorquere/zotero-better-bibtex/issues/1389#issuecomment-580084253 . The singular peaks are not the problem, but the trend is.

It may have something to do with the fact that _attachmentToArray tests whether the file exists, this may be a relatively expensive operation. But it's still surprising to me that it exhibits (what appears to me, I'm not an expert on this) O(n^2) behavior rather than at worst O(n), where base object serialization (item.toJSON) is so fast that it the graph looks like its O(1).
Reply all
Reply to author
Forward
0 new messages