|
| 1 | +# Optimal Performance |
| 2 | + |
| 3 | +There are many advantages to archives. |
| 4 | + |
| 5 | +Open Packages have several performance characteristics worth understanding. |
| 6 | + |
| 7 | +## Reduced Disk Impact |
| 8 | + |
| 9 | +An Open Package is an archive that can be loaded into memory. |
| 10 | + |
| 11 | +When we use OP to Open Packages, we are reading the files into memory. |
| 12 | + |
| 13 | +Please note the plural. |
| 14 | + |
| 15 | +We have an entire filesystem in memory! |
| 16 | + |
| 17 | +This means that every operation on that filesystem is also in memory. |
| 18 | + |
| 19 | +And this means that the disk is involved much less often. |
| 20 | + |
| 21 | +This is especially helpful for home applications and physical servers. |
| 22 | + |
| 23 | +Disks take more time to access than memory. |
| 24 | + |
| 25 | +When dealing with lots of files, this tends to be especially painful. |
| 26 | + |
| 27 | +Each read of the disk could be anywhere, and seek times vary. |
| 28 | + |
| 29 | +By using packages, we eliminate our disk impact. Instead, we impact memory. |
| 30 | + |
| 31 | +## Reduced Memory Impact |
| 32 | + |
| 33 | +Our reduced disk impact makes our reduced memory impact even more priceless. |
| 34 | + |
| 35 | +Normally, if we were mapping files to memory, |
| 36 | +we'd expect to see a memory impact roughly equal to the file size. |
| 37 | + |
| 38 | +You _might_ get clever, and use some light compression. |
| 39 | +At this point you are simply making your own package, anyway. |
| 40 | + |
| 41 | +Because we are storing an _archive_ in memory, |
| 42 | +we are getting compression for free. |
| 43 | + |
| 44 | +The data is all implicitly compressed and decompressed as we read and write content. |
| 45 | + |
| 46 | +This is quite nice! |
| 47 | + |
| 48 | +It also offers some interesting benefits. |
| 49 | + |
| 50 | +## Consistent References |
| 51 | + |
| 52 | +Once a package is loaded into memory, |
| 53 | +every change to that package is to the exact same object. |
| 54 | + |
| 55 | +This means that packages are easy to pass around in memory. |
| 56 | + |
| 57 | +Multiple thread jobs can also access the same package. |
| 58 | + |
| 59 | +Therefore, changes to a loaded package are nearly instant. |
| 60 | + |
| 61 | +The change does not need to propagate, because _it is the same object_. |
| 62 | + |
| 63 | +This is also true for package parts. Once the object exists, we are not recreating it, we are simply sharing a reference to it. |
| 64 | + |
| 65 | +And that reference is consistent. |
| 66 | + |
| 67 | +This enables the core functionality of Open Package: |
| 68 | + |
| 69 | +## Extensible Instances |
| 70 | + |
| 71 | +We can easily extend objects in PowerShell. |
| 72 | + |
| 73 | +This happens in three ways: |
| 74 | + |
| 75 | +1. We can use `Add-Member` to add information to an instance |
| 76 | +2. We can use `Update-TypeData` to add information about a type |
| 77 | +3. We can load a `.types.ps1xml`, which contains type data. |
| 78 | + |
| 79 | +OP is built by extending the types .NET uses to load packages. |
| 80 | + |
| 81 | +Primarily: |
| 82 | + |
| 83 | +* `System.IO.Packaging.Package` |
| 84 | +* `System.IO.Packaging.PackagePart` |
| 85 | + |
| 86 | +Each instance may also `Add-Member` to it's heart's content. |
| 87 | + |
| 88 | +If you want to make your own methods for working with a package, just `Add-Member` |
| 89 | + |
| 90 | +Speaking of adding things, let's talk layers |
| 91 | + |
| 92 | +## Flexible Layering |
| 93 | + |
| 94 | +We can use packages in layers. |
| 95 | + |
| 96 | +This is a lot like how containers work: |
| 97 | +Each layer in a container is effectively a filesystem. |
| 98 | + |
| 99 | +The difference is that, in memory, we can add layers as we need, in any order. |
| 100 | + |
| 101 | +We can allow some packages to be writeable, and others to not be. |
| 102 | + |
| 103 | +We can serve one layer that provides an experience around any files it can fetch. |
| 104 | + |
| 105 | +This can allow us to build applications as layers, instead of making everything a monolith. |
| 106 | + |
| 107 | +We can also swap out layers. |
| 108 | + |
| 109 | +For an example, image a photo viewer. |
| 110 | + |
| 111 | +All it needs to do is render images, but there's lot of ways to do this. |
| 112 | + |
| 113 | +We can easily make a photo viewer as it's own package, |
| 114 | +load it with our package containing photos, |
| 115 | +and have ourselves a gallery! |
| 116 | + |
| 117 | +# Open Possibility |
| 118 | + |
| 119 | +As you can see |
0 commit comments