nvk-struct-cache
v0.0.2
Published
Automatic Structure caching for node-vulkan
Downloads
6
Maintainers
Readme
nvk-struct-cache
🍣 A Rollup plugin for automated Structure caching for node-vulkan
Imagine the following situation:
let commandBuffers = [...Array(8)].map(() => new VkCommandBuffer());
for (let ii = 0; ii < commandBuffers.length; ++ii) {
let commandBufferBeginInfo = new VkCommandBufferBeginInfo();
vkBeginCommandBuffer(commandBuffers[ii], cmdBufferBeginInfo);
};
This results in 8 allocations of VkCommandBufferBeginInfo
structures. When this code gets executed in frequently used code sections, the heap pressure will be high.
Now nvk has a mechanism to simulate stack allocation:
let commandBuffers = [...Array(8)].map(() => new VkCommandBuffer());
for (let ii = 0; ii < commandBuffers.length; ++ii) {
let commandBufferBeginInfo = VkCommandBufferBeginInfo("0x0"); // 0x0 inserted by this package
vkBeginCommandBuffer(commandBuffers[ii], cmdBufferBeginInfo);
};
On the first iteration of the loop, a VkCommandBufferBeginInfo
structure is allocated on the heap but also gets cached internally. Whenever this code gets executed again, the cached structure will be used instead of a new one.
Install
Using npm:
npm install nvk-struct-cache --save-dev
Usage
Create a rollup.config.js
configuration file and import the plugin:
import structCache from "nvk-struct-cache";
export default {
input: "src/index.mjs",
output: {
file: "./bundle.js",
format: "cjs"
},
plugins: [
structCache({ })
]
};