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

Fix memory issues in firefox #1066

Closed
jeswr opened this issue May 3, 2024 · 6 comments
Closed

Fix memory issues in firefox #1066

jeswr opened this issue May 3, 2024 · 6 comments

Comments

@jeswr
Copy link
Collaborator

jeswr commented May 3, 2024

Have been told there are still memory leaks in firefox. This is an issue to investigate.

Please supply details / repros here if you've experienced this issue.

@jeswr
Copy link
Collaborator Author

jeswr commented May 3, 2024

Note that memlab does not currently support firefox which would explain why this is not caught by our CI.

@smeckler
Copy link

smeckler commented May 4, 2024

Thank you for looking into this issue, Jesse.

For testing, you can simply use the example from examples/prebuilt and build a loop around it. Here is a little code snippet: https://pastebin.com/bTgGbVJ6

I tested on Firefox 115.10.0esr (32-bit) with the latest and older eye-js CDN scripts.
On my machine, Firefox consistently runs into memory problems after 6 iterations of the Socrates example. A delay between executions (e.g. 10s) does not change anything. If I use a longer data string, the memory limit is reached after 4-5 iterations.

Stack trace of the memory error:

Uncaught (in promise) RuntimeError: Aborted(out of memory). Build with -sASSERTIONS for more info.
    abort https://eyereasoner.github.io/eye-js/latest/index.js:2
    SWIPL https://eyereasoner.github.io/eye-js/latest/index.js:2
    promise callback*instantiateArrayBuffer https://eyereasoner.github.io/eye-js/latest/index.js:2
    instantiateAsync https://eyereasoner.github.io/eye-js/latest/index.js:2
    createWasm https://eyereasoner.github.io/eye-js/latest/index.js:2
    SWIPL https://eyereasoner.github.io/eye-js/latest/index.js:2
    N https://eyereasoner.github.io/eye-js/latest/index.js:2
    F https://eyereasoner.github.io/eye-js/latest/index.js:2
    n3reasoner https://eyereasoner.github.io/eye-js/latest/index.js:2
    <anonymous> file:///C:/Users/mkl/Downloads/index.html:22

@jeswr
Copy link
Collaborator Author

jeswr commented May 5, 2024

Notes to self:

  • Have been able to repro, happens after about ~250 iterations in the loop for me.
  • The same modified iteration script runs sucessfully in chrome, and taking snapshots of the heap does not show any increases in memory.

Now investigating the cause.

@jeswr
Copy link
Collaborator Author

jeswr commented May 5, 2024

The cause is somewhere in swipl-wasm or it's upstream dependencies, and the memory usage seems to come from instantiating SWIPL. This has been identified by making __test_utils/browser.html be

<!DOCTYPE html>
<html>
  <body>
    <textarea id="data" rows="10" cols="75">
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix : <http://example.org/socrates#>.

:Socrates a :Human.
:Human rdfs:subClassOf :Mortal.

{?A rdfs:subClassOf ?B. ?S a ?A} => {?S a ?B}.</textarea
    >
    <button id="execute">Execute</button>
    <button id="clear">Clear</button>
    <div id="result"></div>
  </body>
  <script src="/index.js"></script>
  <script>
    document.getElementById('execute').addEventListener("click", async () => {
      
      try {
        for (let i = 0; i < 1000; i += 1) {
          if (i % 50 === 0) {
            console.log(i)
          }
          await eyereasoner.SWIPL();
        }
  
        
      } catch (e) {
        console.error(e)
      }
    });

    document.getElementById('clear').addEventListener("click", async () => {
      
      document.getElementById("result").innerHTML = '';

    });
  </script>
</html>

and lib/index.ts be

/* istanbul ignore file */
export * from './query';
export * from './transformers';
export { default as EYE_PVM } from './eye';
export { default as SWIPL } from 'swipl-wasm/dist/swipl/swipl-bundle-no-data';

@jeswr
Copy link
Collaborator Author

jeswr commented May 5, 2024

Progress with this issue can now be tracked in emscripten-core/emscripten#21892. I will open a separate issue on this repo to add a test.

@jeswr
Copy link
Collaborator Author

jeswr commented May 6, 2024

This turned out to be an issue in Firefox - see https://bugzilla.mozilla.org/show_bug.cgi?id=1895309.

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