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

Dart null safety #6696

Merged
merged 7 commits into from
Jun 22, 2021
Merged

Dart null safety #6696

merged 7 commits into from
Jun 22, 2021

Conversation

vaind
Copy link
Contributor

@vaind vaind commented Jun 14, 2021

closes #6282

  • adds null-safety to the library and the generated code
  • plus some minor performance improvements (keeping the rest I've mentioned in the past for a separate PR to limit the scope here)

@github-actions github-actions bot added c++ codegen Involving generating code from schema dart labels Jun 14, 2021
@vaind vaind force-pushed the dart-null-safety branch from e6f7245 to 1f8d751 Compare June 16, 2021 09:19
@vaind vaind marked this pull request as ready for review June 16, 2021 09:49
@vaind vaind changed the title WIP: Dart null safety Dart null safety Jun 16, 2021
@vaind
Copy link
Contributor Author

vaind commented Jun 16, 2021

cc @aardappel @dnfield

@aardappel
Copy link
Collaborator

Generally looks good to me, but would like @dnfield to review.

}

BufferContext._(this._buffer);
BufferContext(this._buffer);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we making this public?

If we need it to be public we should document it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, that slipped in while I've been comparing/merging with the null-safe version from objectbox - it's used there for performance reasons - no need for list of bytes to construct if ByteData is the actually needed interface.

So while this is unrelated to the current PR, I'd leave it here as it doesn't hurt anyone and actually provides a bit of value for lib users. Added a doc comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

SG, docs haven't shown up here yet though (forgot to save/push?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was there and pushed, not sure why it doesn't show up 304056a

@@ -126,15 +129,15 @@ class Builder {

/// The location of the end of the current table, measured in bytes from the
/// end of [_buf], or `null` if a table is not currently being built.
int _currentTableEndTail;
int _currentTableEndTail = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is zero the right sentinel value to use?

Doc comment needs to be updated, since it can't be null anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is never accessed before writing, setting a value just makes it a bit faster internally because dart doesn't have to consider it ever being null. Alternatively, I can change it to late though I guess that comes with some runtime overhead.

@@ -111,7 +113,8 @@ class Builder {

/// The list of existing VTable(s).
//final List<_VTable> _vTables = <_VTable>[];
final List<int> _vTables = <int>[];
final List<int> _vTables = List<int>.filled(16, 0, growable: true)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you don't mind, can you remove the commented out line above this one while you're here?

Also - why are we changing this here? Are there benchmarks that showing a starting size of 16 is better than whatever the core SDK decides to start with?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, removed the commented out code.

Similarly to #6696 (comment) - don't have plain benchmarks with and without this change at the moment, only measured as a whole as part of the larger change suite suggested by mraleph a few months back.

@@ -444,7 +448,7 @@ class Builder {
_maxAlign = 1;
_tail = 0;
_currentVTable = null;
_vTables.clear();
_vTables.length = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this change should be made separately. Clear is the same as this.

Copy link
Contributor Author

@vaind vaind Jun 21, 2021

Choose a reason for hiding this comment

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

Another instance of a change that slipped in from the fork. Coming from some talks with @mraleph (this commit: objectbox/objectbox-dart@a729705#diff-594a84a4fd72af27284e6f59d689b04f9f1f8cfe9dbcdfb512669d16d0f702b0) - I was also a bit confused why setting length was chosen instead of clear but didn't ask at the time. Maybe this mention will prompt a helpful comment from @mraleph? Either way, I'm fine with rolling back to clear() if you want.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it avoids a method invocation? Clear does this internally. Not really a big deal either way, but it might be good to separate out some of these performance related fixes into a separate patch. Not a big deal either way though, this shouldn't hurt anything.

Copy link
Member

Choose a reason for hiding this comment

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

I don't actually remember why I made this change. Most likely clear() was not inlined, can't really find any explanation why I would do it otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would keep it this way if you don't mind. I can create a follow-up PR with the remaining perf improvments

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Left some comments.

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@dnfield dnfield merged commit a6ee335 into google:master Jun 22, 2021
@vaind vaind deleted the dart-null-safety branch June 22, 2021 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ codegen Involving generating code from schema dart
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dart null safety
4 participants