Skip to content

Rewrite MATLAB functions with matlab.io.xml.dom#347

Closed
Jerry1144 wants to merge 5 commits into
trackmate-sc:masterfrom
Jerry1144:rewrite-in-xml-dom
Closed

Rewrite MATLAB functions with matlab.io.xml.dom#347
Jerry1144 wants to merge 5 commits into
trackmate-sc:masterfrom
Jerry1144:rewrite-in-xml-dom

Conversation

@Jerry1144

Copy link
Copy Markdown

Rewrite with matlab.io.xml.dom.* facilities, avoiding Java heap size problems. Available since R2021a. One path to #343. Force-push of #346

A detour from #345 - trackmateEdges requires one table per track node, but it isn't possible to express a parent node's attribute in XPath 1.0, and calling readtable() once per track is slow (50+h from my 16k track file).

Then, to keep the total memory use in check, all function in the series must adhere to a single path. Apparently memory reuse does not happen across readstruct, readtable, and matlab.io.xml.*, and GC only occurs during inactivity. Thus the total rewrite.

It's possible to mix readtable's trackmateSpots.m into this. Used alone it is 5x faster than walking the dom tree ourselves, but when called by trackmateGraph.m it doubles temp memory usage, and slows things down when memory pressure kicks in.

Jerry1144 added 5 commits June 3, 2026 12:58
Circumvent Java heap size problems with recent MATLAB dealing with large XML.

MATLAB's `io.xml.xpath.*` appears to execute eagerly and over-consumes memory
Walking the dom tree ourselves is slower than native `readtable()` when every
sub-node are consolidated into one big table, but the latter cannot easily
handle "one edge table per track" which is required by trackmateEdges.m
Migrate from Java-based `xmlread()` to MATLAB's native `matlab.io.xml.dom.*`.

Minor style change: use 1-based node() instead of 0-based item(), and access
properties directly instead of getProperty().
Revert to querying the nodes with getAttribute().

Strangely, copying the attributes out with getAttributes(), and querying that
copy, is noticeably slower than just repeatedly node.getAttribute().
The correct way to attach the caught ME is error(ME.identifier, ...)
Fixed the missing break-condition check when inspecting the first Spot node.
@Jerry1144 Jerry1144 closed this Jul 3, 2026
@Jerry1144 Jerry1144 deleted the rewrite-in-xml-dom branch July 3, 2026 06:26
@Jerry1144

Copy link
Copy Markdown
Author

Apparently str2double() is a major bottleneck here. Almost every attribute of every node calls it once… Will replace with double(string()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant