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

Improve reference behavior #60

Open
j-f1 opened this issue Sep 16, 2020 · 3 comments
Open

Improve reference behavior #60

j-f1 opened this issue Sep 16, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@j-f1
Copy link
Member

j-f1 commented Sep 16, 2020

I made a small change to report whenever an object ref is deleted:

---
 Runtime/src/index.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Runtime/src/index.ts b/Runtime/src/index.ts
index 0e641ff..ddfba4e 100644
--- a/Runtime/src/index.ts
+++ b/Runtime/src/index.ts
@@ -93,6 +93,7 @@ class SwiftRuntimeHeap {
     release(ref: ref) {
         const value = this._heapValueById.get(ref);
         const isObject = typeof value == "object"
+        console.log('dereferencing', value);
         if (isObject) {
             const entry = this._heapEntryByValue.get(value)!;
             entry.rc--;

(copy the content of the code block and run pbpaste | git apply in your terminal to make this change)

It reports many deallocations. The thing that caught my attention was the repeated deallocation of functions (like toString and hasOwnProperty). I wonder if there’s a way to recognize functions that are part of the JavaScript language and either dynamically call them when needed or mark them so they don’t get released.

@j-f1 j-f1 added the enhancement New feature or request label Sep 16, 2020
@j-f1
Copy link
Member Author

j-f1 commented Sep 16, 2020

I also wonder if we could improve performance by having another Swift → JS calling convention without a return value that avoids the shuffling of memory there.

@MaxDesiatov
Copy link
Contributor

mark them so they don’t get released.

I imagine maintaining a cache of JS functions (a dictionary from their names to function references) could work, but this would prevent monkey patching on the JS side from working. Which is not a great practice anyway, so maybe a cache is fine? 🤔

@j-f1
Copy link
Member Author

j-f1 commented Sep 16, 2020

We could just store the key path to the global value then request it each time Swift asks for it to preserve the ability to monkey patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants