Giter Site home page Giter Site logo

Comments (8)

xiaohk avatar xiaohk commented on July 18, 2024

It also happens to the browser version.

I am not familiar with Emscripten. According to emscripten-core/emscripten#6747 (comment), it seems we need to have some special ways to create arrays to avoid memory growth.

The comments in that issue are very hard to understand 😵‍💫

Here is a demo for this error.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Demo</title>

  <script type="module">

    import GLPK from './index.js';

    (async () => {
      const glpk = await GLPK();

      const modelURL = 'https://gist.githubusercontent.com/xiaohk/73fd07e4d9b35ac572cb9a927db45462/raw/71b83b13d1601c7ed6c73194983157eeef534123/model.json';
      let result = await fetch(modelURL);
      let modelData = await result.json();

      // Error happens when i = 13
      for (let i = 0; i < 15; i++) {
        console.log(i);
        let pResult = await glpk.solve(modelData);
        console.log(pResult);
      }

      document.querySelector('#output').innerHTML = `
        Hello World!
      `;
    })()

  </script>
</head>

<body>
  <textarea id="output" style="width: 800px; height: 500px" readonly></textarea>
</body>

</html>

from glpk.js.

jvail avatar jvail commented on July 18, 2024

Hi @xiaohk, thanks for the example. I have never had a memory issue even with large LPs so I will definitely try to fix this one if I can find the issue. Maybe there were changes in the current emscripten regarding memory handling that I am was not aware of when I made the new release.

from glpk.js.

xiaohk avatar xiaohk commented on July 18, 2024

Hi @jvail, thank you so much for your quick reply! Really appreciate your continuing support and maintenance! I am not familiar with C or C++, but I will also help as I can. Based on emscripten-core/emscripten#6747 (comment), the following array initialization might be worth looking into.

glpk.js/src/glpk.js

Lines 96 to 104 in eabefee

let ind_ = new Int32Array(ind);
let ind_ptr = _malloc(ind_.length * ind_.BYTES_PER_ELEMENT);
let ind_data = new Uint8Array(HEAPU8.buffer, ind_ptr, ind_.length * ind_.BYTES_PER_ELEMENT);
ind_data.set(new Uint8Array(ind_.buffer));
let val_ = new Float64Array(val);
let val_ptr = _malloc(val_.length * val_.BYTES_PER_ELEMENT);
let val_data = new Uint8Array(HEAPU8.buffer, val_ptr, val_.length * val_.BYTES_PER_ELEMENT);
val_data.set(new Uint8Array(val_.buffer));

from glpk.js.

jvail avatar jvail commented on July 18, 2024

Hi, yes, you are right. I can reproduce it and it happens in line 98. What I do not understand why it needs grow memory if you run the same LP over and over. Maybe there is a more severe issue with freeing memory. I'll debug it but it might take some time. Can I use your LP file as a test case later?

from glpk.js.

xiaohk avatar xiaohk commented on July 18, 2024

Hi, yes, you are right. I can reproduce it and it happens in line 98. What I do not understand why it needs grow memory if you run the same LP over and over. Maybe there is a more severe issue with freeing memory. I'll debug it but it might take some time. Can I use your LP file as a test case later?

Sure! Thank you 🙌

from glpk.js.

jvail avatar jvail commented on July 18, 2024

Hi @xiaohk, I am still puzzled why this issue appears now but it seems to be gone now. Apparently I made a big mistake and did not free the memory properly - so, thanks for reporting the bug. Would you like to give it a try and checkout the dev branch to test if it works for you now?

from glpk.js.

xiaohk avatar xiaohk commented on July 18, 2024

Hi @xiaohk, I am still puzzled why this issue appears now but it seems to be gone now. Apparently I made a big mistake and did not free the memory properly - so, thanks for reporting the bug. Would you like to give it a try and checkout the dev branch to test if it works for you now?

Amazing! 680de13 is working for me now. Thank you so much for your quick reply and fix!

from glpk.js.

jvail avatar jvail commented on July 18, 2024

@xiaohk Sure, no problem, thanks for reporting & testing 👍

from glpk.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.