Skip to content

Do not set a default which the struct already holds - #29

Merged
nickyoung-github merged 3 commits into
masterfrom
feature/skip-defaults
Nov 30, 2026
Merged

nickyoung-github merged 3 commits into
masterfrom
feature/skip-defaults

Conversation

@nickyoung-github

Copy link
Copy Markdown
Owner

Making an object with many defaults is quicker: a field which is given its default is no longer set, as the struct which is generated already holds it.

On an Apple M1, of extensions built for release, in nanoseconds:

Make C++, before C++, now Rust, before Rust, now
Trade, of 19 fields, 14 of them defaults 3,568 2,451 4,006 2,955
Money, of 2 300 304 431 438
Customer, of 5 338 337 563 551

How

  • When a class is bound, the runtime makes a native object and reads each of its fields. Where one is the class's default, the descriptor is told so.
  • The descriptor then sets nothing when it is given that default, and the struct's field is still what it is of a struct newly made.
  • So it is right of an object which is not frozen, of which a field may be set back to its default; and of an extension built before a default was changed, of which that default is set as before. Defaults are still not of the schema's hash.
  • A default is told by which object it is, or by what it equals if it is of a default_factory. One held by reference is not skipped, unless it is None or holds nothing.
  • In C++ and in Rust alike. The descriptors written in Python do not do it.

With what is already built

An extension built by 1.2.0 works with this runtime, and one built by this with the runtime of 1.2.0: neither then skips.

Also

The crate is 1.3.0, as its source has changed, and the README's Performance tables are of a new run.

Tested, for C++ and for Rust: a field of an object which is not frozen, set to another value and back to its default; and a class of another default than its extension was built with, which has its own. The tests which are for every mode pass as before. Checked by hand: of 1,650 values given to the fields of four classes, each is taken or refused as before, and alike by C++ and Rust.

…-tag

Take the crate's version from the tag when it is released
@nickyoung-github
nickyoung-github merged commit 7201c6d into master Nov 30, 2026
6 checks passed
@nickyoung-github
nickyoung-github deleted the feature/skip-defaults branch November 30, 2026 11:06
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.

1 participant