Should Elm pagination use Array.slice or List.take/drop with Lazy for large datasets?
0 reputation · 09 May 2025, 18:25 UTC
Implementing pagination for a large dataset in an Elm frontend requires choosing a data structure that balances access speed, memory allocation, and code simplicity. The core List module provides take and drop that traverse from the head each time, which can become costly for long lists, while Array.slice offers logarithmic access but creates a new Array copy of the requested range, potentially increasing memory churn if pages are retained.
Developers can mitigate list traversal costs with the Lazy module to defer construction of unused elements, yet this adds indirection and may complicate updates when the underlying data changes. The trade‑off between these approaches is not clearly documented for typical use cases where users navigate forward and backward through many pages and old pages may stay referenced until the view changes.
Which approach yields better overall performance for paginated lists of 100 000+ items? How does memory usage compare when multiple pages are kept in memory? Is there a recommended pattern for releasing references to old pages to avoid unnecessary retention?