Conversation
For a property restricted to a base type, `prop_validate()` called `class_inherits()` to check the underlying type and then called the base class validator, which checked exactly the same thing again. `class_inherits(x, <base class>)` is defined as `what$class == base_class(x)`, and every base class validator is the auto-generated `if (base_class(object) != <name>)` check produced by `new_base_class()` (the only call sites are base.R and base-environment.R). So once `class_inherits()` passes there is nothing left for the validator to reject, and it can be skipped. `class_validate()` was already a no-op for unions, `class_any`, `class_missing`, and `NULL`, so those stay on the general path. Also tighten `validate_properties()`: return early when a class has no properties, and only grow `errors` when a property actually fails (it was doing `c(errors, NULL)` on every iteration). wide50 411us -> 224us, wide10 114us -> 76us.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype for #723.
This is stacked on the functional commits from #737 and #743 and should be rebased once those PRs land.
Classes cache construction metadata in the environment-backed class reference introduced by #743:
new_object()uses the cache to avoid rediscovering setters and storage names, and skips validation when a concrete parent is already valid and the child adds neither properties nor a validator.validate_properties()uses the cached validation plan and directly reads stored attributes for ordinary non-S4 objects, avoiding repeated genericprop()lookups.Benchmarks
I ran
bench/constructor.Rback-to-back against the combined #737 + #743 baseline and this prototype on arm64 with R 4.5.3.The cached metadata increases marginal class-graph memory by approximately 17%. A production version could likely reduce that by using more compact parallel vectors or moving some of the validation plan into C.
Validation
air format .devtools::test(): 1,289 passedgit diff --check