Skip to content

Commit

Permalink
Prune outlet connections during gc and clean up graph node interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-thompson committed Oct 31, 2024
1 parent a8923b8 commit d507db3
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,24 @@ Float32Array [
27,
]
`;

exports[`mc table 4`] = `
Float32Array [
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
42,
]
`;
22 changes: 22 additions & 0 deletions js/packages/offline-renderer/__tests__/mc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ test("mc table", async function () {
// Process another small block
core.process(inps, outs);
expect(outs[0]).toMatchSnapshot();

// Now here we expect that the first graph has been totally nudged out
// of relevance, except for the nodes that remain shared which are the table
// and the const 0. If we gc then, we should remove that add() and root() from
// the original graph.
expect(await core.gc()).toEqual([1611541315, 1811703364]);

// But now the act of removing that add node should have pruned the outlet connections
// list on the table node. We'll test that original graph again to ensure that after
// rebuilding that connection everything still looks good.
await core.render(
el.add(...el.mc.table({ path: "/v/stereo", channels: 2 }, 0)),
);

// Get past the fade-in
for (let i = 0; i < 100; ++i) {
core.process(inps, outs);
}

// Process another small block
core.process(inps, outs);
expect(outs[0]).toMatchSnapshot();
});

test("mc sampleseq", async function () {
Expand Down
2 changes: 1 addition & 1 deletion js/packages/offline-renderer/elementary-wasm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/packages/web-renderer/raw/elementary-wasm.js

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions runtime/elem/GraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ namespace elem
double getSampleRate() { return sampleRate; }
size_t getBlockSize() { return blockSize; }

//==============================================================================
// Returns the number of output channels this node will write to
virtual size_t getNumOutputChannels() { return 1; }

//==============================================================================
// Sets a property onto the graph node.
//
Expand Down
30 changes: 27 additions & 3 deletions runtime/elem/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,33 @@ namespace elem
// active graph rendering sequence have multiple references, while those
// that are unused are held only by the nodeTable. Those nodes we clean up here.
for (auto it = nodeTable.begin(); it != nodeTable.end(); /* skip increment */) {
if (it->second.node.use_count() == 1) {
ELEM_DBG("[Native] gc " << nodeIdToHex(it->second.node->getId()));
pruned.insert(it->first);
auto& nodeId = it->first;
auto& entry = it->second;

if (entry.node.use_count() == 1) {
ELEM_DBG("[Native] gc " << nodeIdToHex(nodeId));
pruned.insert(nodeId);

// Update the adjacency list to remove the parent pointers from each
// of the removed node's children.
for (auto& inlet : entry.inlets) {
auto& childId = inlet.source;

// It's possible we already removed the child in this same gc pass
if (nodeTable.count(childId) > 0) {
auto& childEntry = nodeTable.at(childId);
childEntry.outlets.erase(
std::remove_if(
childEntry.outlets.begin(),
childEntry.outlets.end(),
[&](auto const& outlet) {
return outlet.destination == nodeId;
}
)
);
}
}

it = nodeTable.erase(it);
} else {
it++;
Expand Down
5 changes: 0 additions & 5 deletions runtime/elem/builtins/mc/SampleSeq.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ namespace elem
}
}

size_t getNumOutputChannels() override
{
return 2;
}

int setProperty(std::string const& key, js::Value const& val, SharedResourceMap& resources) override
{
if constexpr (WithStretch) {
Expand Down
5 changes: 0 additions & 5 deletions runtime/elem/builtins/mc/Table.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ namespace elem
struct StereoTableNode : public GraphNode<FloatType> {
using GraphNode<FloatType>::GraphNode;

size_t getNumOutputChannels() override
{
return 2;
}

int setProperty(std::string const& key, js::Value const& val, SharedResourceMap& resources) override
{
if (key == "path") {
Expand Down

0 comments on commit d507db3

Please sign in to comment.