Skip to content

Eliminate runtime reflection in Operators#27

Merged
ctrueden merged 4 commits into
scijava:mainfrom
JaredDavis22:eliminatereflection
Jul 19, 2026
Merged

Eliminate runtime reflection in Operators#27
ctrueden merged 4 commits into
scijava:mainfrom
JaredDavis22:eliminatereflection

Conversation

@JaredDavis22

Copy link
Copy Markdown
Contributor

Eliminate reflection during runtime. A test is added to ensure the manually maintained list in Operators remains in sync with the declared Operator entries.

@ctrueden

ctrueden commented Jul 17, 2026

Copy link
Copy Markdown
Member

What is the rationale for this change? Does it improve performance? It is a net increase of 42 lines of code, and makes the codebase less DRY. Is it just because people consider reflection to be ugly or ill-advised? If the issue is that repeated calls to standardList() are not cached, it would be less code to keep the new private static List<Operator> operatorList populated lazily at the first call to standardList().

@ctrueden

ctrueden commented Jul 17, 2026

Copy link
Copy Markdown
Member

See also related discussion at #24 (comment), which explains that this change does improve performance. But if we cache the calculated-via-reflection list, I feel like that should achieve the vast majority of the performance gain. (Is standardList() being called more than once?)

@JaredDavis22

JaredDavis22 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

When we can shift anything from runtime to compile time, we should. Reflection can be made to hit less. But, it will always be an unnecessary hit.

Eliminating reflection from the main code makes the project easier to understand imho. When you see the list, you know what is going on. The test code reflection will remind the programmer if they added an operator but did not add it to the list.

GraalVM may or may not work as is with the reflection. I know it will work 100% with the list approach.

How often has the list changed over the years?

@ctrueden
ctrueden force-pushed the eliminatereflection branch from 8387aac to 883ce78 Compare July 19, 2026 18:11
@ctrueden
ctrueden force-pushed the eliminatereflection branch from 883ce78 to 0d5ae61 Compare July 19, 2026 20:49
@ctrueden

Copy link
Copy Markdown
Member

@JaredDavis22 I found a way of doing what you want here, without explicitly replicating the list of operators. Please take a look and let me know what you think. If you like it, I'll merge this.

@JaredDavis22

Copy link
Copy Markdown
Contributor Author

Looks great. Thanks. Do we still need reflection in OperatorsTest with this solution?

@ctrueden

Copy link
Copy Markdown
Member

Do we still need reflection in OperatorsTest with this solution?

Nah, I think we're OK without it!

@ctrueden
ctrueden merged commit fe31a5a into scijava:main Jul 19, 2026
1 check passed
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.

2 participants