# Optimize asChunksOf with JavaScript slice

**URL:** <https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802>\
**Category:** Development\
**Created:** [August 27, 2025, 5:22pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802 "2025-08-27T17:22:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![derv](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/derv/32/8400_2.png) [@derv](https://forum.snap.berkeley.edu/u/derv)\
**Post date:** [August 27, 2025, 5:22pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/1 "2025-08-27T17:22:02Z")

</div>

This optimization is portable to other functions. However, there are potential issues with list mutability.

> <https://github.com/jmoenig/Snap/pull/3479>
>
> \# Other notes
> This fixes bounds checking; 2D arrays cannot be reshaped to negat…ive width and height anymore.

---

<div class="post-metadata">

**Author:** ![derv](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/derv/32/8400_2.png) [@derv](https://forum.snap.berkeley.edu/u/derv)\
**Post date:** [August 27, 2025, 5:26pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/2 "2025-08-27T17:26:04Z")

</div>

Actually, there could be a way to implement mutability-based optimizations on a scoped basis. This would match languages like Rust, but may be confusing for beginners.

Maybe add this as a parameter for the List constructor? If a hypothetical low-level change was approved, I could implement typed lists: “generic”, “cloning”, and “mutating”. Generic lists would need to be wrapped in the other two types to be usable with most other blocks.

---

<div class="post-metadata">

**Author:** ![tethrarxitet](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/tethrarxitet/32/45543_2.png) [@tethrarxitet](https://forum.snap.berkeley.edu/u/tethrarxitet)\
**Post date:** [August 27, 2025, 5:44pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/3 "2025-08-27T17:44:34Z")

</div>

Nice! Can you show a comparison between the fixed version and the original version?... wait, can basic users do this?

---

<div class="post-metadata">

**Author:** ![derv](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/derv/32/8400_2.png) [@derv](https://forum.snap.berkeley.edu/u/derv)\
**Post date:** [August 27, 2025, 5:46pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/4 "2025-08-27T17:46:25Z")

</div>

i miscalculated the optimizations again, ignore (wrong number of repeats)

---

<div class="post-metadata">

**Author:** ![bh](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/bh/32/31580_2.png) [@bh](https://forum.snap.berkeley.edu/u/bh)\
**Post date:** [August 27, 2025, 8:12pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/5 "2025-08-27T20:12:48Z")

</div>

> Maybe add this as a parameter for the List constructor? If a hypothetical low-level change was approved, I could implement typed lists: “generic”, “cloning”, and “mutating”. Generic lists would need to be wrapped in the other two types to be usable with most other blocks.

The whole point of hybrid lists is that users shouldn't have to think about how the list is stored; it's just a sequence abstraction, and it's the language's job to make sure it's stored efficiently. So I think complicating the LIST constructor would be counterproductive.

(Side note: It strikes me that I keep inventing features with "hybrid" in their names: hybrid lists (long since implemented), hybrid scope (rejected by Jens), hybrid primitives (was on the list for a long time, but recently implemented). I wonder what this says about my psychology.)

---

<div class="post-metadata">

**Author:** ![jens](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/jens/32/39797_2.png) [@jens](https://forum.snap.berkeley.edu/u/jens)\
**Post date:** [August 27, 2025, 8:21pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/6 "2025-08-27T20:21:07Z")

</div>

Maybe “hybrid” is just a fancy word for getting it both ways, having your cake and eating it, too! 🙂

---

<div class="post-metadata">

**Author:** ![bh](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/bh/32/31580_2.png) [@bh](https://forum.snap.berkeley.edu/u/bh)\
**Post date:** [August 27, 2025, 9:14pm UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/7 "2025-08-27T21:14:23Z")

</div>

True enough!

---

<div class="post-metadata">

**Author:** ![derv](https://forum.snap.berkeley.edu/user_avatar/forum.snap.berkeley.edu/derv/32/8400_2.png) [@derv](https://forum.snap.berkeley.edu/u/derv)\
**Post date:** [August 28, 2025, 1:31am UTC](https://forum.snap.berkeley.edu/t/optimize-aschunksof-with-javascript-slice/19802/8 "2025-08-28T01:31:58Z")

</div>

My de-abstraction suggestion doesn’t fit in this project’s scope, so I will reconsider where I apply the concepts of lists.
