Optimize datatype CLI performance by skipping accessor loop for 0-ary constructors #7710
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a significant performance regression in the CLI when declaring datatypes with many 0-ary constructors (constructors with no arguments).
Problem
The issue was identified through profiling data showing that
cmd_context::dt_eh::operator()was spending excessive time in:datatype::util::get_constructor_recognizer(67.03% of time, 8743 calls)datatype::util::get_constructor_accessors(36.53% of time, 5600 calls)For datatypes with many 0-ary constructors like:
The CLI was taking 4+ seconds for 50,000 constructors and 14+ seconds for 100,000 constructors, while the API could handle 100,000 constructors in just 300ms.
Root Cause
The performance bottleneck was in
cmd_context::dt_eh::operator()where the code was callingget_constructor_accessors()and iterating through the results for every constructor, including 0-ary constructors that have no accessors by definition.Solution
Added a simple check
if (c->get_arity() > 0)before callingget_constructor_accessors()and iterating through accessors:This avoids the expensive accessor lookup and empty loop iteration for 0-ary constructors while preserving full functionality for constructors that do have accessors.
Performance Results
Validation
Fixes #7709.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.