You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The comparison behavior described above has not changed.
178
-
179
-
The comparability of records and tuples is a very useful property when dealing with data structures. However, relying on the runtime type information is not an ideal solution.
177
+
The comparison behavior described above has not changed. The comparability of records and tuples is useful when dealing with data structures. However, relying on the runtime type information is not an ideal solution.
180
178
181
179
Since record types are much broader than primitive types, we need a new approach beyond the unified operators.
182
180
183
-
The compiler fully understands the structure of each record type so it can generate optimized code. Imagine Rust's `#[derive(Eq)]` but for ReScript.
181
+
This won't be included in the v12 release, but we'd like to share an idea we're exploring. Imagine Rust's `#[derive(Eq)]` but for ReScript. As the compiler fully understands the structure of each record type, it can generate optimized code for each type.
184
182
185
183
```res
186
184
@deriving([compare, equals])
@@ -203,15 +201,11 @@ function person$equals(a, b) {
203
201
}
204
202
```
205
203
206
-
The compiler can perform the same specialization used in unified operators and generate code where the comparison operation is used. So `(a :> person) < b` is expected to be `person$compare(a, b) < 0` or fully inlined as it is less complex than a certain threshold.
204
+
Then, the compiler performs the same specialization used in unified operators and generates code where the comparison operation is used. So `(a :> person) < b` is expected to be `person$compare(a, b) < 0` or fully inlined as it is less complex than a certain threshold.
207
205
208
206
The example is over-simplified, but it should work equally well with more complex, nested structures or sum types.
209
207
210
-
### Efficient React memoization
211
-
212
-
One possible use case for generated comparison operators is React apps.
213
-
214
-
Using complex types in production apps can result in significant performance degradation, as ReScript ADTs are not compatible with React's memoization behavior.
208
+
One possible use case for generated comparison operators is React apps. Using complex types in production apps can result in significant performance degradation, as ReScript ADTs are not compatible with React's memoization behavior.
0 commit comments