-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]help wantedIndicates that a maintainer wants help on an issue or pull requestIndicates that a maintainer wants help on an issue or pull requestperformanceMust go fasterMust go faster
Description
There's a clever trick that we could use to create large zero matrices really fast: mmap the file /dev/zero. This is, in fact, exactly what this "file" exists for. The benefit of doing this are:
- It's nearly instantaneous since no memory actually needs to be allocated or filled with zeros until it's accessed.
- You can read and write the memory exactly as you normally would: the kernel only allocates memory pages for you when you do something with them.
Since a fair amount of the time, no one actually touches most of the memory in a zeros array, this might be a big win. On the other hand, the drawbacks are:
- Trade obvious immediate allocation cost for unobvious delayed allocation cost.
- Can run out of memory on read/write instead of only on allocate.
- Doesn't work for anything but
zeros(), e.g. forones().
RoyiAvital, cossio, alex-s-gardner and PallHaraldsson
Metadata
Metadata
Assignees
Labels
arrays[a, r, r, a, y, s][a, r, r, a, y, s]help wantedIndicates that a maintainer wants help on an issue or pull requestIndicates that a maintainer wants help on an issue or pull requestperformanceMust go fasterMust go faster