Skip to content

Instantly share code, notes, and snippets.

View Malien's full-sized avatar
🍌
what am I doing here?

Yaroslav Petryk Malien

🍌
what am I doing here?
  • National University of Kyiv-Mohyla Academy
  • Kyiv
View GitHub Profile
@Malien
Malien / cartesian.swift
Last active October 24, 2024 14:30
Variadic type-safe eager cartesian product in Swift 6
func liftOptional<each Ts>(_ values: repeat (each Ts)?) -> (repeat each Ts)? {
for value in repeat each values {
if value == nil { return nil }
}
return (repeat (each values)!)
}
struct PartialResult<each Element> {
var contents: (repeat (each Element)?)
@Malien
Malien / IDB Bulk Extraction Takeaways.md
Last active July 24, 2024 10:13
IDB Bulk Extraction Benchmark

Was trying to see which method for bulk retrieving data from IndexedDB would perform the best on different data distribution.

Key takeaways:

  • Use Promise.all(keys.map(key => store.get(key))) for most cases (random lookups or even contigiuos-ish cases are mostly fine).
  • Use store.get(KeyRange.bound(lower, upper) when you know you are interested in a contigious range.
  • Avoid cursor API whenever possible. If you are fine with a bit more memory usage, just fetch everything via getAll() and do filtering afterwards.
  • The chunked retrieval is honestly pretty descent, for contigious/contigiuos-ish lookups.
  • When the loads start to look like full-table retrieval (ie. retrieving 80% of the records), Promise.all starts to fall behind. Consider doing full-table retrieval, or, if you are memory constrained, chunked iteration/full-table scan via getAll or cursor API.

Duh.