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

Make classes sealed, methods static & avoid array allocations where possible, dispose disposable, other optimizations & clean up usings #687

Closed
wants to merge 3 commits into from

Conversation

Henr1k80
Copy link
Contributor

I was surprised to see how popular this package is and I would like to try reduce the carbon impact of it.
It might not be directly measurable, but the compound impact of all the executions hopefully makes a difference 🤞🏻

  • Where possible:

    • Classes sealed
    • Methods static
    • Avoid unneeded array allocations
  • Dispose disposable

  • Other minor optimizations™®©

  • Clean up usings

There should be no breaking changes, unless you do reflection hacks and that should not be a supported use case.

@stakx
Copy link
Member

stakx commented Sep 20, 2024

Hi @Henr1k80 and thanks for contributing! ✨

A couple points:

  • Making classes sealed or declaring them static where possible is a change to the public contract. We could schedule such changes for the next major version release, but earlier than that I think that the cost (avoidable breaking changes) outweighs the benefit (cleaner and perhaps minutely faster code).
  • DictionaryAdapter is pretty much legacy by now, I personally have no interest in developing this further, including doing code reviews on it. (Sorry.) Maybe someone else wants to invest their time here?
  • Avoiding unnecessary array allocations sounds great! Let's do this.

So I think it would be great if you could split up this PR into several ones, each dealing with one specific aspect so that we can deal with them separately

  • I'd be happy to review and merge one focusing on unnecessary array allocations.
  • I'd be willing to do the same for one focusing on sealed/static etc. but only at a later time (when we're planning the next major version).
  • I'm reluctant about a PR doing things to DictionaryAdapter. But if there's enough general interest and support for it, I could perhaps be talked into it.

OK for you to proceed like this? If so, I'd be closing this PR in favor of the upcoming one(s).

@Henr1k80
Copy link
Contributor Author

Henr1k80 commented Sep 20, 2024

Hi @stakx

Making classes sealed or declaring them static where possible is a change to the public contract. We could schedule such changes for the next major version release, but earlier than that I think that the cost (avoidable breaking changes) outweighs the benefit (cleaner and perhaps minutely faster code).

I have been very meticulous securing that there are no changes to the public contract, only internal & private classes have been made sealed and static. There are no changes to the unit tests, an indication of nothing changed.
The only exceptions are the public classes that only contains consts. There are no code changes needed for accessing these consts.

@stakx
Copy link
Member

stakx commented Sep 20, 2024

@Henr1k80, see the changes in the ref/ files. Those are indications that there are indeed changes to the public contract (API surface). Unit tests still passing is obviously important, but does by itself not guarantee that the API surface has remained unchanged.

My above points and the question re: whether to proceed as suggested still stand.

@Henr1k80
Copy link
Contributor Author

@stakx ok, I understand your concerns and have removed the changes that affect the ref/ files

@stakx
Copy link
Member

stakx commented Oct 19, 2024

@Henr1k80, you have since submitted separate PRs addressing the same concerns raised in this PR, so I am going to close this one as it is now duplicated by the others.

@stakx stakx closed this Oct 19, 2024
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