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

Add memoization to Cache #1720

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Add memoization to Cache #1720

wants to merge 11 commits into from

Conversation

Jym77
Copy link
Contributor

@Jym77 Jym77 commented Nov 25, 2024

No description provided.

Copy link

changeset-bot bot commented Nov 25, 2024

🦋 Changeset detected

Latest commit: 83540d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 77 packages
Name Type
@siteimprove/alfa-cache Minor
@siteimprove/alfa-aria Minor
@siteimprove/alfa-cascade Minor
@siteimprove/alfa-dom Minor
@siteimprove/alfa-rules Minor
@siteimprove/alfa-selector Minor
@siteimprove/alfa-style Minor
@siteimprove/alfa-table Minor
@siteimprove/alfa-web Minor
@siteimprove/alfa-act Minor
@siteimprove/alfa-affine Minor
@siteimprove/alfa-applicative Minor
@siteimprove/alfa-array Minor
@siteimprove/alfa-bits Minor
@siteimprove/alfa-branched Minor
@siteimprove/alfa-callback Minor
@siteimprove/alfa-clone Minor
@siteimprove/alfa-collection Minor
@siteimprove/alfa-comparable Minor
@siteimprove/alfa-compatibility Minor
@siteimprove/alfa-continuation Minor
@siteimprove/alfa-css-feature Minor
@siteimprove/alfa-css Minor
@siteimprove/alfa-device Minor
@siteimprove/alfa-earl Minor
@siteimprove/alfa-either Minor
@siteimprove/alfa-emitter Minor
@siteimprove/alfa-encoding Minor
@siteimprove/alfa-equatable Minor
@siteimprove/alfa-flags Minor
@siteimprove/alfa-fnv Minor
@siteimprove/alfa-foldable Minor
@siteimprove/alfa-functor Minor
@siteimprove/alfa-future Minor
@siteimprove/alfa-generator Minor
@siteimprove/alfa-graph Minor
@siteimprove/alfa-hash Minor
@siteimprove/alfa-http Minor
@siteimprove/alfa-iana Minor
@siteimprove/alfa-iterable Minor
@siteimprove/alfa-json-ld Minor
@siteimprove/alfa-json Minor
@siteimprove/alfa-lazy Minor
@siteimprove/alfa-list Minor
@siteimprove/alfa-map Minor
@siteimprove/alfa-mapper Minor
@siteimprove/alfa-math Minor
@siteimprove/alfa-monad Minor
@siteimprove/alfa-network Minor
@siteimprove/alfa-option Minor
@siteimprove/alfa-parser Minor
@siteimprove/alfa-performance Minor
@siteimprove/alfa-predicate Minor
@siteimprove/alfa-promise Minor
@siteimprove/alfa-record Minor
@siteimprove/alfa-rectangle Minor
@siteimprove/alfa-reducer Minor
@siteimprove/alfa-refinement Minor
@siteimprove/alfa-result Minor
@siteimprove/alfa-sarif Minor
@siteimprove/alfa-selective Minor
@siteimprove/alfa-sequence Minor
@siteimprove/alfa-set Minor
@siteimprove/alfa-slice Minor
@siteimprove/alfa-string Minor
@siteimprove/alfa-test Minor
@siteimprove/alfa-thenable Minor
@siteimprove/alfa-thunk Minor
@siteimprove/alfa-time Minor
@siteimprove/alfa-toolchain Minor
@siteimprove/alfa-trampoline Minor
@siteimprove/alfa-tree Minor
@siteimprove/alfa-trilean Minor
@siteimprove/alfa-tuple Minor
@siteimprove/alfa-url Minor
@siteimprove/alfa-wcag Minor
@siteimprove/alfa-xpath Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Jym77 Jym77 self-assigned this Nov 25, 2024
@Jym77 Jym77 added the minor Backwards-compatible change that touches public API label Nov 25, 2024
Comment on lines 61 to 65
const hasHiddenAncestors = Cache.memoize<
unknown,
[Device, Context],
Predicate<Node>
>(_hasHiddenAncestors);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure why TS needs some skaffolding here, but not in the simple cases in the tests 🤷

const cache = Cache.empty<Device, Cache<Context, Cache<Node, boolean>>>();

function hasHiddenAncestors(
function _hasHiddenAncestors(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a demo of using the new decorator, not directly related to the changes.

@Jym77 Jym77 marked this pull request as ready for review November 25, 2024 14:45
@Jym77 Jym77 requested a review from a team as a code owner November 25, 2024 14:45
@Jym77 Jym77 changed the title Add memoization to Cache. Add memoization to Cache Nov 25, 2024
),
// Or its parent is programmatically hidden
(node: Node) =>
node.parent(Node.fullTree).some(_hasHiddenAncestors(device, context)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Is it on purpose the call is to _hasHiddenAncestors and not hasHiddenAncestors? I can't tell if it makes a difference, but in the original code, in the recursion the cache would be used, but now it's going to recurse without the cache, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ouch. Good point. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Backwards-compatible change that touches public API
Projects
Status: 🧑‍💻 Doing
Development

Successfully merging this pull request may close these issues.

2 participants