Comments (3)
it is also less performant than implementing the same functionality using data structures from Ruby (e.g. list of constants)
The most common operation done with enum values is to compare them (either directly with ==
, or indirectly via case
/when
/===
)
T::Enum#==
and T::Enum#===
can be made just as fast as comparing string/symbol constants (in either case, it just uses the identity-based comparison inherited from Object#==
).
I explore this in https://github.com/Shopify/shopify-types/pull/454/files , but had trouble getting CI to validate my changes. Perhaps that's worth exploring first?
I think that change (having #==
and #===
only be overridden when T::Configuration.legacy_t_enum_migration_mode?
is set) can even be upstreamed into sorbet/sorbet.
from rubocop-sorbet.
@amomchilov That's really interesting! I will take a look at this as it ties in well with our Sorbet performance project. I wonder if we could apply the same logic to the <=>
method? I did some benchmarks where <
/>
comparisons were 8x slower with T::Enum
values than constants, which was pretty wild to me.
from rubocop-sorbet.
Hmm, when is <=>
even used? T::Enum
doesn't even include Comparable
from rubocop-sorbet.
Related Issues (20)
- Migrate from `RuboCop::Cop::Cop` to `RuboCop::Cop::Base`
- `EnforceSignatures` cop doesn't detect `sig(:final)` HOT 2
- Publish version 1.0
- Sorbet/ConstantsFromStrings does not catch &.constantize
- Integration with the Sorbet LSP
- Sigil cops ignore double commented sigils
- Discourage references to `ActiveRecord::Associations::CollectionProxy` and other synthetic constants
- EmptyLineAfterSig does't recognize `attr` declarations
- Consider a cop to detect stubbing of `is_a?`
- Forbid defining implicit conversion methods (to_ary, to_hash, to_int, to_str) HOT 1
- ValidSigil parsing behaves differently than sorbet sigil parsing
- Sorbet/AllowIncompatibleOverride inspection error HOT 2
- Suggestion: Cop for `sig` as a single or multi-line block
- Sorbet/ForbidTStruct - autocorrect does not handle optional params without default or factory HOT 1
- Enforce parentheses around return values in signatures HOT 1
- Suggestion: Cop for missing `require "sorbet-runtime"` HOT 6
- Patch `Performance/RedundantBlockCall` to teach it about Sorbet `sig`s HOT 1
- Suggested cop: prefer `first`/`drop`/`last` over `[]` with particular kinds of ranges
- Explain EnforceSigilOrder better in documentation HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rubocop-sorbet.