Skip to content
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

[FLINK-37438] Improve the createLocalEnvironment by reduce duplicate operation on Configuration #26273

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

beliefer
Copy link
Contributor

@beliefer beliefer commented Mar 8, 2025

What is the purpose of the change

This PR proposes to improve the createLocalEnvironment by reduce duplicate operation on Configuration.

Brief change log

Improve the createLocalEnvironment by reduce duplicate operation on Configuration
Currently, StreamExecutionEnvironment provides a createLocalEnvironment with one parameter parallelism.

    public static LocalStreamEnvironment createLocalEnvironment(int parallelism) {
        return createLocalEnvironment(parallelism, new Configuration());
    }

Above method will create a new instance of Configuration and then calling the below override one.

    public static LocalStreamEnvironment createLocalEnvironment(
            int parallelism, Configuration configuration) {
        Configuration copyOfConfiguration = new Configuration();
        copyOfConfiguration.addAll(configuration);
        copyOfConfiguration.set(CoreOptions.DEFAULT_PARALLELISM, parallelism);
        return createLocalEnvironment(copyOfConfiguration);
    }

The second will create another instance of Configuration and name it with copyOfConfiguration.
You can see add configuration into copyOfConfiguration with addAll.
The issue is create Configuration duplicately and an extra operation addAll.

Verifying this change

This change is already covered by existing tests, such as ExpressionTestBase.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@flinkbot
Copy link
Collaborator

flinkbot commented Mar 8, 2025

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

@beliefer
Copy link
Contributor Author

beliefer commented Mar 8, 2025

ping @1996fanrui cc @davidradl

return createLocalEnvironment(parallelism, new Configuration());
Configuration configuration = new Configuration();
configuration.set(CoreOptions.DEFAULT_PARALLELISM, parallelism);
return createLocalEnvironment(configuration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Or
return createLocalEnvironment(new Configuration().set(CoreOptions.DEFAULT_PARALLELISM, parallelism));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidradl @1996fanrui
Does Flink have any coding style preferences for this style?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beliefer I found https://flink.apache.org/how-to-contribute/code-style-and-quality-java/ but it does not include this example.

I was only thinking to not define variables if we can avoid it. As the committer @1996fanrui WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Flink have any coding style preferences for this style?

I didn't see the strict style preference for this case. I like @davidradl 's suggestion because we could avoid one temporary variable.

Copy link
Contributor Author

@beliefer beliefer Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@1996fanrui 1996fanrui self-assigned this Mar 10, 2025
Copy link
Member

@1996fanrui 1996fanrui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the refactor!

LGTM

@1996fanrui
Copy link
Member

1996fanrui commented Mar 14, 2025

Hi @davidradl , do you have any comment about this PR?

I will merge it next Monday if no more comment.

@1996fanrui 1996fanrui merged commit 452b648 into apache:master Mar 17, 2025
@beliefer
Copy link
Contributor Author

@1996fanrui @davidradl Thank you all!

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

Successfully merging this pull request may close these issues.

4 participants