Skip to content

redundant-object incorrectly counts references within recursive formations, causing performance issues #1132

Description

@yegor256

misc/redundant-object.xsl:16 reports an object as redundant when
count(key('referenced-by-name', @name)) <= 1, that is, when the whole
document mentions its name once. The count is purely syntactic, so it treats a
lone reference sitting inside a recursive formation the same as a lone
reference in straight-line code.

Those two are not the same. Take eo-runtime/src/main/eo/number/arc-sine.eo:45
in objectionary/eo, where point.times point > squared is declared beside the
recursive helper poly and referenced exactly once, from inside poly. The
lint says it "may be inlined". Following that advice is a mistake: poly
recurses thirty levels, and while the named attribute gives all thirty levels
one shared series.squared node, the inlined form gives each level its own copy
of the point.times point subgraph nested inside the previous level. Running
the eo-runtime suite with the object inlined takes EOarc_sineTest from about
9 seconds to 189, and under the parallel suite the JVM exhausts its heap.

The smallest fix is to skip the defect when the single reference lies inside a
formation that is an ancestor-or-self of a recursive one — that is, when the
referring node has an ancestor o whose own name appears in the @base of one
of its descendants. This is not the same gap as #639 and #640, which are about
references the lint fails to see at all; here the reference is counted
correctly, but one syntactic mention is many dynamic ones.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood-titleThe title was checked and improved by ChatGPT

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions