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

maybe perf tuning | strict ifs #974

Closed

Conversation

lifeart
Copy link
Contributor

@lifeart lifeart commented Sep 25, 2019

@pzuraq is it make sence?

// #964

Copy link
Member

@pzuraq pzuraq left a comment

Choose a reason for hiding this comment

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

I believe this makes sense, but would like to get some weigh in from the other core team members before merging. Thanks for doing this though! I wonder if we could write a lint rule for this

@krisselden
Copy link
Contributor

in general for hotspots the explicit checks are better than falsy coercions, especially if you have several types that falsy coerce and one of them happens occasionally.

packages/@glimmer/reference/lib/reference.ts Outdated Show resolved Hide resolved
packages/@glimmer/runtime/lib/vm/stack.ts Outdated Show resolved Hide resolved
@pzuraq
Copy link
Member

pzuraq commented Oct 4, 2019

@lifeart can you add that eslint rule in this PR? It should allow the cases that Kris pointed out, where we know the value is always a boolean, but prevent all the other cases where we don't know and end up coercing.

@lifeart lifeart force-pushed the strict-ifs-possible-perf-improvements branch from 0b56320 to 98582e2 Compare October 4, 2019 22:57
@lifeart
Copy link
Contributor Author

lifeart commented Oct 4, 2019

Don't know why GH showing conflict for tslint.json

@lifeart lifeart force-pushed the strict-ifs-possible-perf-improvements branch 3 times, most recently from 633a977 to 4fdee1c Compare October 7, 2019 04:59
@lifeart lifeart force-pushed the strict-ifs-possible-perf-improvements branch from f25e24b to 780b6a1 Compare October 7, 2019 07:57
@lifeart
Copy link
Contributor Author

lifeart commented Oct 7, 2019

@krisselden, @pzuraq done.

@lifeart lifeart requested review from pzuraq and krisselden October 7, 2019 08:45
@@ -9,6 +9,10 @@ import { StringLiteral, BooleanLiteral, NumberLiteral } from './types/handlebars
export type BuilderPath = string | AST.PathExpression;
export type TagDescriptor = string | { name: string; selfClosing: boolean };

function withFallback<T, U>(originalValue: T | null | undefined, fallbackValue: U): T | U {
Copy link
Member

Choose a reason for hiding this comment

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

We should consider changing this to nullish coalescing once TS 3.7 is released

Copy link
Member

@pzuraq pzuraq left a comment

Choose a reason for hiding this comment

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

I think this generally looks good. I was a bit hesitant about using Array.isArray so much compared to checking against null/undefined, but it appears that in all the places where it's being used the type of the value it's checking is actually already supposed to be an array, so I'm not sure what it should be comparing in the first place (seems like either the types are off, or those checks are unnecessary)

@lifeart lifeart closed this Sep 7, 2020
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.

3 participants