findLinksByExample performance

Hello,

Long story short, our diagram is sometimes asked to add the same link twice. So, on each add link request, I want to add a check like this

// linksToAdd is an array of links we will add to the diagram
linksToAdd = linksToAdd.filter(link => !diagram.findLinksByExample(link)?.count)

Since this will happen every time the diagram is given a new node, I wanted to know if I need to consider performance impact. I read GoJS Performance Considerations -- Northwoods Software but just wanted to double check.

From what I’ve heard, findNodeForKey and findLinkForKey are very performant (constant time) since they utilize a lookup table. Is findLinksByExample similarly performant or at least sufficiently performant in that it should not matter? Our use case is typically adding fewer than 25 links at a time and the diagram typically contains fewer than 1000 links, but it would be nice to know if there is a consideration at a larger scale as well.

You are correct that all lookups by key are constant-time. However Diagram.find…ByExample are linear searches, at least at the current time. If you find it becomes too slow for how often you call it, you will need to do your own search that is smarter because you can make assumptions that the library cannot know about.

But I suggest not making premature optimizations until you have proven they are needed.