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

Example of complex pattern for untagged variant. #6240

Merged
merged 5 commits into from
Jun 22, 2023

Conversation

cristianoc
Copy link
Collaborator

From #6108

@cristianoc cristianoc requested a review from zth May 3, 2023 03:05
@cristianoc
Copy link
Collaborator Author

@zth see examples of simplifications in the various commits.

Some things to think about:

  • how much simpler is the overall function?
  • how ad-hoc are these simplifications?
  • one needs to cast a wider net beyond booleans, and consider more cases of pattern matching.

Basically, the question is of return on investment. What do you think?

var match$1 = s[1];
if ((match$1 === null || typeof match$1 !== "object") && match$1 === false) {
if (match$1 === false) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

@zth
Copy link
Collaborator

zth commented May 3, 2023

These are good questions. I'd say it looks quite a lot simpler. But, I don't have good answers for the rest of the questions... Is this type of optimization very specific to just these cases?

@cristianoc
Copy link
Collaborator Author

asking our friend

Pros:

  1. Code simplification: The PR significantly simplifies the generated JavaScript code, making it easier to read and understand, as well as potentially improving performance.
  2. Better pattern matching: The PR improves the pattern matching, potentially leading to more efficient code execution and a better developer experience.
  3. Incremental improvements: Proceeding with this PR is a step towards optimizing the compiler further, paving the way for future enhancements and optimizations.

Cons:

  1. Ad-hoc nature: The simplifications made in this PR might be too specific to the given test case and not applicable to a broader range of cases, which might limit the overall impact of the optimizations.
  2. Maintenance burden: The PR adds new code that needs to be maintained, which could increase the complexity of the compiler codebase and make future modifications more difficult.
  3. Unexplored cases: There might be other, more general optimizations that could be applied to the compiler. Proceeding with this PR might divert focus from discovering and implementing these more general solutions.

@cristianoc
Copy link
Collaborator Author

How about exploring more cases next? Can you give me another example that falls outside what this PR does? E.g. not only booleans.
Also, is the example code OK now or is there something else to optimise?

@zth
Copy link
Collaborator

zth commented May 10, 2023

Coming back to this soon.

@zth
Copy link
Collaborator

zth commented Jun 21, 2023

Haven't been able to figure out a good other example. This does feel like a nice improvement as is. What about merging this and then continuing with more examples later on?

@cristianoc cristianoc force-pushed the complex_pattern_untagged branch from b904343 to ad80be2 Compare June 22, 2023 00:53
@cristianoc cristianoc merged commit 3af3f3b into master Jun 22, 2023
@cristianoc cristianoc deleted the complex_pattern_untagged branch June 22, 2023 00:58
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