#ShallowCopy
A 𝐡𝐚𝐫𝐝 exercise to help build the right mental model for Python data.
- Solution: memory-graph.com#codeurl=http...
- Explanation: github.com/bterwijn/mem...

#PythonDev #memory_graph #ShallowCopy
September 25, 2026 at 10:49 AM
An exercise to help build the right mental model for Python data.
- Solution: memory-graph.com#codeurl=http...
- Explanation: github.com/bterwijn/mem...

#PythonDev #memory_graph #ShallowCopy
September 23, 2026 at 4:40 PM
An exercise to help build the right mental model for Python data.
- Solution: memory-graph.com#codeurl=http...
- Explanation: github.com/bterwijn/mem...

#PythonDev #memory_graph #ShallowCopy
September 20, 2026 at 3:05 AM
An exercise to help build the right mental model for Python data.
- Solution: memory-graph.com#codeurl=http...
- Explanation: github.com/bterwijn/mem...

The Solution link uses 𝗺𝗲𝗺𝗼𝗿𝘆_𝗴𝗿𝗮𝗽𝗵: github.com/bterwijn/mem...
to visualize code execution.

#PythonDev #memory_graph #ShallowCopy #DeepCopy
September 16, 2026 at 11:38 PM
shallowCopy & deepCopy in JavaScript
**ShallowCopy** When we copy an object to a variable and then change the value using that variable, the original object's values also change. This happens because we're not copying the actual data—we're just copying the object's reference (the memory address). So, both the original object and the new variable point to the same data in memory. To avoid this, we use a shallow copy, which creates a new object with the same values, so changes to the new object don’t affect the original one **Problem statement** let obj = { name: "saurabh" }; let user = obj; name.name = "sachin"; console.log(obj); //output is sachin **Solution** **1. Solution** let obj = { name: "saurabh" } let user = {...obj} user.name = "sachin" console.log(obj) //output will be saurabh **2. Solution** let obj = { name: "saurabh" } let user = object.assign({},obj); user.name="sachin" console.log(obj) //output will be saurabh **Deep Copy** A shallow copy won't be enough if an object has nested objects (objects inside objects). That’s because a shallow copy only copies the top-level properties. The nested objects are still copied by reference. So, if we change a value inside a nested object in the copied version, it will still affect the original object. To avoid this, we use a deep copy, which copies everything, including all nested objects. This way, the copied object is completely separate from the original, and changes won’t affect each other. **Problem statement** let obj = { name: "Saurabh", address: { city: "Pune", state: "MH" } }; let user = {...obj} user.address.city = "Mumbai" console.log (obj) //output will be obj, city will be changed to Mumbai **Solution** let obj = { name: "Saurabh" address: { city: "Pune" State: "MH" } } let user = JSON.parse(JSON.Stringfy(obj)); user.address.city = "Mumbai" console.log(obj) // output remains the same as the obj will not change
forem.com
April 19, 2025 at 9:32 AM
I've spent a ton of time trying out alternate impls for Immer's `shallowCopy()`, as it becomes a bottleneck with larger objs.

Filed a draft PR with a proposed change to `Obj.keys().forEach()` instead of `{...}`, and a long writeup with details and confusion:

github.com/immerjs/imme...
Implement optional strings-only shallow copies for perf by markerikson · Pull Request #1188 · immerjs/immer
This PR: Adds new options for the StrictMode shallow copying option: "with_symbols" is an alias for the current strict: false behavior "full" is an alias for the current stric...
github.com
October 28, 2025 at 3:35 AM
Interesting! Does that make the fast-path slower, or the slow-path faster?

Specifically, for Immer's `shallowCopy`, I'm trying to figure out the best balance for "copies plain objects fast all the time" vs "works well for large objects"
October 27, 2025 at 11:43 PM
Constant change - it's a generic shallowCopy util used for literally every single value that Immer updates.

Yeah, wouldn't surprise me if that somehow defeats a potential shape specialization
October 12, 2025 at 5:57 PM
but I'm staring at actual results dropping that into Immer and seeing the total `shallowCopy` time drop by at least half in some stress tests.

no explanation for this, but okay, sure, let's go with it :)
October 12, 2025 at 5:00 PM
Aqui, por algum motivo, eles importam TUDO do lodash. Mas usam só um isEqual ou um shallowCopy no máximo.

Mas mesmo importando um a um, lodash é muito pesado (74kb), sendo que tem 99% no Nativo.

Antigamente era util, hoje em dia nem tanto . . .
September 14, 2024 at 4:21 AM
I just completed "Guard Gallivant" - Day 6 - Advent of Code 2024 #AdventOfCode adventofcode.com/2024/day/6

Learned a very humbling lesson about the difference between deepcopy and shallowcopy in python. 🫠
Day 6 - Advent of Code 2024
adventofcode.com
December 6, 2024 at 1:45 PM