-
-
Notifications
You must be signed in to change notification settings - Fork 99
Implement copy-on-write for all backends #157
Copy link
Copy link
Closed
Description
While I love value semantics and still thinks it is best to avoid this type of questions:

I think:
- easy syntax,
- behaviour consistency between backends (Cpu, Cuda, OpenCL),
- efficient memory allocation
- and performance
cannot be ignored.
Most Arraymancer performance issues come from memory allocation and are due to value semantics. The alternative, using unsafeView, unsafeSlice, unsafeSqueeze, etc is clunky as it litters the codebase with low-level details.
With "copy-on-write", it is possible to be:
- safe as with value semantics
- and fast like reference semantics
by only copying when necessary, i.e. when a value is mutable.
Benefits expected:
- Copies involving non-mutable variables will be shallow by default
- Slicing of non-mutable variables will be shallow by default
- Everything involving mutable variables will be deep by default to prevent "unexpected surprises"
- Keep the behaviour predictable:
- let assignment from let ==> shallow
- var assignment from let ==> deep
- let assignment from var ==> deep
- There will be no under the hood
if refcount = 1optimization for var assignment .
That would make Arraymancer depends on the refcounting GC and it would be much better to use destructors and the future=moveand=sinkin Implement=moveand=sinkoperators (destructors) #150 for that.
- Copy-on-write will work well with unsafe proc chaining unsafe proc chaining -> first proc unsafe = all procs unsafe #151
Limitations:
- Implicit
resultwill still requireunsafeViewandunsafeUnsqueezefor shallow-copies. (Obviously slice mutation does not copy but overwrite in-place).
This is perfectly reasonable in my opinion.
This superseeds #19
Reactions are currently unavailable