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

Better representation of Int64 on platforms that support unboxed int64 integers #172

Open
mkustermann opened this issue Feb 2, 2023 · 2 comments
Labels
package:fixnum type-enhancement A request for a change that isn't a bug

Comments

@mkustermann
Copy link
Member

The current implementation of Int64 stores the underlying integer as 3 integer fields:

class Int64 implements IntX {
  // A 64-bit integer is represented internally as three non-negative
  // integers, storing the 22 low, 22 middle, and 20 high bits of the
  // 64-bit value.

  final int _l, _m, _h;
  ...
}

Operations to/from a Dart int as well as arithmetic/bitwise operations will be slow due to need to operate on the combination of three fields.

On platforms such as the Dart VM or Dart2WasmGC we have support for unboxed int64 values where this overhead can be entirely avoided.

There's two improvements

  • Use e.g. conditional imports to select better representation for Int64 on VM / Dart2WasmGC than for Dart2Js
  • Possibly avoid the creation of Int64 boxes entirely by having mechanism to pass unboxed values around

/cc @askeksa-google (since we just talked about it), @osa1 , @mraleph

@mkustermann mkustermann added the type-enhancement A request for a change that isn't a bug label Feb 2, 2023
@mraleph
Copy link
Member

mraleph commented Feb 2, 2023

I think it is related (duplicate of #169).

I think with inline class we could even consider going all in and making Int64 an unboxed value. It's going to be a breaking change but much smaller one then before.

@mkustermann
Copy link
Member Author

I think with inline class we could even consider going all in and making Int64 an unboxed value. It's going to be a breaking change but much smaller one then before.

I was thinking the same. But inline classes afaik are restricted to one member, so for dart2js one still needs multiple integers to represent an int64. Maybe it could be one inline class that is either based on unboxed int64 on VM or on a boxed value for dart2js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:fixnum type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants