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

use LazyMap in extension constructors #45

Closed
wants to merge 1 commit into from
Closed

use LazyMap in extension constructors #45

wants to merge 1 commit into from

Conversation

jakemac53
Copy link
Contributor

We don't have a benchmark and might want to wait to land this until we do. Thoughts?

Mostly just wanted to hack on something for the last bit of my day 🤣

@jakemac53 jakemac53 requested a review from davidmorgan August 15, 2024 22:39
if (code != null) 'code': code,
});
}) : this.fromJson(LazyMap(
[
Copy link
Contributor Author

@jakemac53 jakemac53 Aug 15, 2024

Choose a reason for hiding this comment

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

Fwiw, I don't love that we will allocate a list still for each call to these. It might be worth trying to some up with something better?

Copy link
Member

@rakudrama rakudrama Aug 16, 2024

Choose a reason for hiding this comment

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

The code also allocates a closure over this.
The per-object closure could be fixed by making this and explicit argument to the closure, and using a static method.

Calling the closure for each present key is likely to be O(N^2) as the switch-on-string generally compiles to an if-then-else chain on the string comparisons. For small N, no problem, but at some point all the string comparisons will dominate,

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I was thinking along these lines yesterday, it was great to find an implementation in my inbox this morning, I spent today adding some benchmarking on top and exploring a third way, writeup here

#48

tl;dr this is already nearly 3x faster than using standard maps; I think we can get rid of the list+closure using extension type builders, and it does give some further speedup, to 3.5x; still some way from proving that it works though, input and suggestions welcome :)

Copy link
Contributor Author

@jakemac53 jakemac53 Aug 16, 2024

Choose a reason for hiding this comment

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

The code also allocates a closure over this.

Is that still true given this is a redirecting constructor on an extension type? There is no this in scope.

Calling the closure for each present key is likely to be O(N^2) as the switch-on-string generally compiles to an if-then-else chain on the string comparisons. For small N, no problem, but at some point all the string comparisons will dominate,

For sure, but the number of keys is never going to be very large here, so I think it should be fine.

Thanks! I was thinking along these lines yesterday, it was great to find an implementation in my inbox this morning, I spent today adding some benchmarking on top and exploring a third way, writeup here

Cool, will take a look :)

@davidmorgan
Copy link
Contributor

I think this is obsoleted by #51

It's nevertheless useful to benchmark with, I based one benchmark in #52 on the generated code here.

@jakemac53 jakemac53 closed this Aug 28, 2024
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