Comments (9)
What you say seems right to me, ST shouldn't be nondeterministic. I've seen a suprising lot of code that uses new
instead of one of the default value vector creation functions.
I'd also like to mention that libc
's memset
and friends are extremely fast as they use SSE and upwards, so initialising by default will likely be a very small penalty, assuming you will completely read or write the vector at least once afterwards.
from vector.
I've been contemplating how best to fix this issue. I can see two or three ways, so I'd like some input.
The problem is that new
is implemented in Generic
. So if we want this to be resolved via an unsafe
designation, we need an operation that can be called generically for this purpose.
One possibility is clear
. This is currently a no-op on unboxed vectors, but we could make it zero out the array instead. Then new
could call clear
. This would be a bit slower, presumably, for arrays where this isn't necessary, but that may not matter.
A second option is to introduce a new operation that zeroes out unboxed arrays and no-ops on others.
A third option is to fix this even for unsafe
operations, and just have basicUnsafeNew
zero out unboxed arrays. This makes you unable to say, 'trust me,' for these. But that might not matter, either.
Does anyone have a strong preference for any of these solutions?
from vector.
So, I'm having trouble actually verifying that this problem exists. Are we sure that GHC or something below it isn't zeroing the memory already?
I wrote some test cases where I allocate new primitive vectors and sum them, and I always get 0 as an answer. Have you seen something different, @rwbarton? I'm using 7.8.3, but maybe older versions worked differently (or newer ones do)? I suppose it could also be OS dependent?
from vector.
Okay, apparently if you're using ghci, the memory will not be zeroed, but memory appears to be zeroed in compiled programs. The situation is the same for Storable
vectors.
Never mind. My test case wasn't good enough. I can reproduce this in compiled programs. Storable
is definitely also affected, though.
from vector.
I was testing in ghci, but yeah, the OS will zero newly-allocated pages it hands you, so the unallocated area of the nursery is likely to be zeroed initially, but not after the first GC.
from vector.
I have a fairly strong preference for maintaining a "trust me" option (to maintain the "performance at any cost" theme of this package). Repurposing the unsafe
names for this sounds good to me personally, but uninitialized
sounds fine too.
from vector.
The problem, last I checked, is that fixing this while leaving an escape hatch requires adding operations to be very good. You need a generic initialize
function that will do things for unboxed vectors and not for boxed vectors (because they are already initialized). It's rather more nice to fix by making even unsafeNew
initialize the memory.
I also question whether array allocation is ever a bottleneck that requires "performance at any cost." And we need something like that to justify the more complicated solution.
from vector.
I imagine it could be significant in an array-doubling situation like an unfold.
from vector.
This has been fixed. Released in 0.11.0.0.
from vector.
Related Issues (20)
- High level documentation? HOT 1
- overlaps for Data.Vector.Mutable behaves oddly for empty vectors HOT 2
- Performance issues with `foldl'` and large tuples HOT 3
- Add a variant unfoldrExactN, returning the resulting generator HOT 3
- Vector tests take more than 4GB memory to build HOT 3
- `Data.Vector.Fusion.Bundle.Size.Size` fields are not strict HOT 1
- Why is `Data.Vector.Generic.New.New` not a newtype? HOT 2
- Question: Is there a reason why `Unbox a => Maybe (Unbox a)` doesn't exist? HOT 1
- Is `vector` susceptible to the same fusion problems as `text`? HOT 2
- Improve compilation time HOT 3
- Split generic tests into separate package HOT 5
- Tests fail when built against QuickCheck-2.14.3 HOT 2
- New version vector 0.14? HOT 11
- Support `primitive-0.9` HOT 1
- Semantics and implementation of move for SoA vectors
- API using Applicative (traverse et.al.)
- Add total counterparts to partial functions, such as `head`. HOT 25
- catMaybes HOT 2
- Add strict boxed vectors HOT 12
- Data.Vector.Generic.New.unstream (and others) can't be specialized HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vector.