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

A thought re sub refs passed in #12

Open
shadowcat-mst opened this issue Jul 25, 2024 · 1 comment
Open

A thought re sub refs passed in #12

shadowcat-mst opened this issue Jul 25, 2024 · 1 comment

Comments

@shadowcat-mst
Copy link

While I think most of the warnings would/should still apply, I think you could get -mostly- timely destruction for them.

The trick would be to keep a WeakMap or WeakSet of the javascript functions proxying to the subref on the JS side, plus a hash or Hash::Util::FieldHash of the subrefs themselves on the perl side, and to periodically check to see if the WeakXXX entry has gone away and release the subref if so.

Sadly I don't immediately see a way to convince QuickJS to do a full GC, so you'll be dependent on its decision for that, but since it's a hybrid refcounting + mark&sweep GC (and perl programmers tend to reflexively -not- create circular references if we can avoid it ;) there seems like a decent chance that the function object will go away at a sensibly early moment - or at least often enough that at least with a little care such a feature would be worth turning on for quite a lot of users.

The question of whether this is worth the additional complexity is left as an exercise to the maintainer - but nonetheless, I'm pretty sure it would -work- at least.

(I am not currently using this module but was having a look around; it -is- now filed in my brain as the first thing to try when I need something in this space, but that doesn't mean you should listen to me if your actual users don't care ;)

(I have a project in mind that absolutely would end up using this, hence looking around, but whether the yak ordering will result in me writing it any time soon is unknown)

@FGasper
Copy link
Owner

FGasper commented Jul 30, 2024

Of potential interest:

bellard/quickjs#337

It's an interesting idea. Probably not something I'd do myself--to many other irons in the fire--but I'd be happy to look at a PR.

Alternatively, as I no longer use Perl for $work, someone with a bigger stake in this module could assume maintainership.

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

No branches or pull requests

2 participants