-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register type definitions lazily #11938
Register type definitions lazily #11938
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Few style-like comments inline. Treat as opinions.
- Overall this seems like the right change.
- what's the impact on benchmarks?
- explicitly: what's the impact on
test/Benchmarks/src/Startup/*.enso
startups?
* @param annotations the list of attached annotations | ||
* @param args the list of argument definitions | ||
*/ | ||
public record InitializationParts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this new record have to be public? Because the record
defines not just public constructor, but also public getters. I do not think we want people around the code base to call the getters.
enso/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/function/FunctionSchema.java
Line 235 in 0c41e8d
public static final class Builder { |
Could we rather follow this example by @Akirathan where Pavel introduced FunctionSchema.Builder
?
* @return the supplier providing the value with the mapping function applied | ||
* @param <R> the result type | ||
*/ | ||
public <R> CachingSupplier<R> map(Function<T, R> f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "tendency towards functional style" is clear...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I, on the other hand, really like it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are benchmark regressions and the only change that doesn't seem straightforward to me is this map
method. But of course, I may be biased...
this.constructorFunction = | ||
buildConstructorFunction( | ||
language, section, localScope, scopeBuilder, assignments, varReads, annotations, args); | ||
initializationResultSupplier.map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting use of the new map
function. The alternative would be to have a single field Supplier<InitializationResult>
stored in the AtomConstructor
. I seem to like it a bit more - shows the "fixed" vs. the lazily computed part of the structure.
new RuntimeAnnotation(annotation.name, closureRootNode) | ||
} | ||
|
||
new InitializationParts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the builder style, this would become:
AtomConstructor.newBuilder().
section(...).
scope(...).
assignments(...).
reads(...).
args(defs);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Agree with @JaroslavTulach on the commenteds about style. You don't have to schedule the benchmarks and compare them on this PR, but remember to please at least add a comment on this PR about the results.
Here is the benchmarks run, although I'm not sure how to compare it to the reference values https://github.com/enso-org/enso/actions/runs/12528446812
|
@Akirathan has provided the information here.
I've just tried:
there are many slowdowns. Looks like allocations of atoms are slower than then used to be. There is another set of benchmarks including startup benchmarks. Run following CI action and then generate comparition with:
At least the startup benchmarks should show some improvement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to eliminate the performance regressions before integrating.
/** Builder required for initialization of the atom constructor. */ | ||
public static final class InitializationBuilder { | ||
|
||
private final SourceSection section; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
fields are good.
this.args = args; | ||
} | ||
|
||
private SourceSection getSection() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the getters aren't really necessary and one could access directly the private
fields.
* @return the supplier providing the value with the mapping function applied | ||
* @param <R> the result type | ||
*/ | ||
public <R> CachingSupplier<R> map(Function<T, R> f) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are benchmark regressions and the only change that doesn't seem straightforward to me is this map
method. But of course, I may be biased...
@@ -278,8 +384,9 @@ public String toString() { | |||
* | |||
* @return the constructor function of this constructor. | |||
*/ | |||
@TruffleBoundary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param varReads the expressions that read field values from local vars | ||
* @param initializationBuilderSupplier the function supplying the parts required for | ||
* initialization | ||
* @param fieldNames the argument names | ||
* @return {@code this}, for convenience | ||
*/ | ||
public AtomConstructor initializeFields( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can initializeFields
be private now, when there is the builder?
On my machine, after removing truffle boundaries b94f81f it is:
Before:
|
engine/runtime/src/main/java/org/enso/interpreter/runtime/data/atom/AtomConstructor.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no regression in engine benchmarks and there is some speedup in startup then feel free to integrate in current state.
Startup benchmark results are about the same:
|
Pull Request Description
close #10923
Changelog:
registerTypeDefinitions
registers constructors lazilyImportant Notes
The improvement of time spent in the
registerTypeDefinitions
method (highlighted):before
after
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.