Skip to content

refactor(pass-style): faster isObject#2860

Merged
erights merged 3 commits into
masterfrom
markm-speed-up-something
Jun 24, 2025
Merged

refactor(pass-style): faster isObject#2860
erights merged 3 commits into
masterfrom
markm-speed-up-something

Conversation

@erights

@erights erights commented Jun 16, 2025

Copy link
Copy Markdown
Contributor

Closes: #XXXX
Refs: Agoric/agoric-sdk#11497

Description

Experiment with possible endo speedups. This was originally motivated to try for fewer benchmark errors in Agoric/agoric-sdk#11497 vs Agoric/agoric-sdk#11459 . However, the relevant bottleneck for those, while still not diagnosed, is not addressed or affected by this PR.

Nevertheless, according to @gibson042 's comment at #2860 (review) below

This change has minor impact in V8, but Object(value) must be very slow in XS because the speedup there is significant.

Since we care most of all about performance in XS, this change is worth it.

Security Considerations

none

Scaling Considerations

No change to complexity measure, so no change to "scaling" per se. But more colloquially, we include in "scaling" a significant performance improvement.

Documentation Considerations

In light of @gibson042 's suggestion below, this PR will deprecate isObject, export isPrimitive as the inverted replacement, because the name is clearer, and will switch all current callers of isObject to call isPrimitive instead. This should be reflected in the generated typedoc commentary.

Testing Considerations

None.

Compatibility Considerations

Because we're only deprecating isObject, and because we make no change to its observable behavior, none.

Upgrade Considerations

  • Update NEWS.md with isPrimitive and the deprecation of isObject.

@gibson042 gibson042 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change has minor impact in V8, but Object(value) must be very slow in XS because the speedup there is significant.

Comment thread packages/pass-style/src/passStyle-helpers.js Outdated
Comment thread packages/pass-style/src/passStyle-helpers.js Outdated
Comment thread packages/pass-style/src/passStyle-helpers.js
@erights erights changed the title refactor(pass-style): possibly faster isObject refactor(pass-style): faster isObject Jun 24, 2025
@erights erights force-pushed the markm-speed-up-something branch from 3859088 to c68c807 Compare June 24, 2025 02:32
@erights erights marked this pull request as ready for review June 24, 2025 02:32


const { details: X, Fail } = assert;
export { X, Fail } from '@endo/errors';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a pure-refactor drive-by

// Note that this step will fail if `specimen` would be a passable container
// except that it contains non-passable errors that could be converted.
// This will need to be fixed to do the TODO above.
const passStyle = /** @type {PassStyle} */ (passStyleOf(specimen));

@erights erights Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moving the call to passStyleOf inside the conditional is a drive-by. But typescript's imprecision about the negation of an is result type provoked the extra cast.

/**
* The actual JS primitive types.
*/
export type JSPrimitive =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Made it easier to define the type of isPrimitive.

if (!isObject(obj)) {
throw TypeError(`Object expected: ${path}, ${obj}, ${protoName}`);
if (isPrimitive(obj)) {
throw TypeError(`Object expected: ${path}, ${String(obj)}, ${protoName}`);

@erights erights Jun 24, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The better typing of isPrimitive (thanks @gibson042) provoked typescript into reporting this genuine bug as a type error. So this bug fix is more than a drive-by.

@erights erights force-pushed the markm-speed-up-something branch from c68c807 to ccbf2e5 Compare June 24, 2025 02:46
@erights erights enabled auto-merge (squash) June 24, 2025 03:22
@erights erights merged commit 5efcf7d into master Jun 24, 2025
16 checks passed
@erights erights deleted the markm-speed-up-something branch June 24, 2025 03:30
erights added a commit that referenced this pull request Jul 16, 2025
Closes: #XXXX
Refs: #2860

## Description

#2860 deprecated `isObject` as confusing and promoted use of
`isPrimitive` instead. However, it also made the type of `isObject` more
precise, which accidentally broken a bunch of client code in agoric-sdk
(and possibly elsewhere) that relied on the type being less precise.
Since `isObject` is now deprecated and all clients should eventually
switch to `!isPrimitive` anyway, it costs nothing to lose this extra
type precision of `isObject`.

This PR restores the old imprecise type.

### Security Considerations

none
### Scaling Considerations

none
### Documentation Considerations

none
### Testing Considerations

none
### Compatibility Considerations

The point. This PR restores the compatibility that #2860 accidentally
broke.
### Upgrade Considerations

none
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.

3 participants