# \#cow

**URL:** https://forums.swift.org/tag/cow/532.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Copy-on-write implementation choice](https://forums.swift.org/t/copy-on-write-implementation-choice/76335)

<div class="topic-metadata">

**Author:** [@mobc](https://forums.swift.org/u/mobc)\
**Replies:** 6\
**Last updated:** [December 4, 2024, 8:15am UTC](https://forums.swift.org/t/copy-on-write-implementation-choice/76335 "2024-12-04T08:15:36Z")

</div>

Hi everyone, I’m currently trying to understand Copy-on-Write (COW) behavior, and I’ve come across two different implementations. I was wondering why some people might prefer the first approach over the second. Here’s …

---

## [Conditional copy/clone on write](https://forums.swift.org/t/conditional-copy-clone-on-write/72120)

<div class="topic-metadata">

**Author:** [@carsonfarmer](https://forums.swift.org/u/carsonfarmer)\
**Replies:** 17\
**Last updated:** [June 1, 2024, 12:28pm UTC](https://forums.swift.org/t/conditional-copy-clone-on-write/72120 "2024-06-01T12:28:34Z")

</div>

I am currently (re)-implementing a persistent binary tree data structure in Swift, and in the simplest case, I'm already seeing pretty good performance with entirely safe code. This is awesome (my naive implementation is…

---

## [More efficient local array?](https://forums.swift.org/t/more-efficient-local-array/67298)

<div class="topic-metadata">

**Author:** [@bbrk24](https://forums.swift.org/u/bbrk24)\
**Replies:** 4\
**Last updated:** [September 15, 2023, 5:02pm UTC](https://forums.swift.org/t/more-efficient-local-array/67298 "2023-09-15T17:02:51Z")

</div>

After banging my head against some code's performance for several hours, I realized that close to half of my runtime is spent doing refcounting/CoW operations on some arrays and dictionaries. These are local variables th…

---

## [Avoiding COW in MutableCollection's slice setter](https://forums.swift.org/t/avoiding-cow-in-mutablecollections-slice-setter/49587)

<div class="topic-metadata">

**Author:** [@Karl](https://forums.swift.org/u/Karl)\
**Replies:** 2\
**Last updated:** [June 14, 2021, 7:45am UTC](https://forums.swift.org/t/avoiding-cow-in-mutablecollections-slice-setter/49587 "2021-06-14T07:45:55Z")

</div>

I have an algorithm to collapse duplicate elements in a collection. I couldn't find anything in the standard library that would help with this, so the solution I came up with is to iterate the collection, finding ranges…
