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

Win10 DLL invoke very slow #43

Open
ximinchao opened this issue Jan 4, 2019 · 0 comments
Open

Win10 DLL invoke very slow #43

ximinchao opened this issue Jan 4, 2019 · 0 comments

Comments

@ximinchao
Copy link

ximinchao commented Jan 4, 2019

Hi, thanks to the developers, I found fastcall very convenient to use, it's a greate lib. But I encoutered a strange issue recently. I'm using fastcall on win10 to invoke my DLL in node.js, in the DLL there are funcitons doing some time-consuming operations. I found some strange issues when I test them using different test tools.

  1. Mocha
    The DLL function invoked all right in DLL-layer, but it takes very long time to swith to node enviroment and to go through the rest of the test case.
  2. Jest
    The DLL function invoked all right in DLL and node layer, so the test case goes well.

ffi works well for both mocha and jest

My enviroment:

  • node: 10.2.1
  • jest: 23.6.0
  • mocha: 5.2.0
  • fastcall: 0.2.6

I wrote a sample here:

https://github.com/ximinchao/FastCallTest

DLL code


int TestAdd(int a, int b) {
	Sleep(2000);
	return a + b;
}

node.js code


const path = require("path");
const fastcall = require("fastcall");
const Library = fastcall.Library;

const lib = new Library(path.resolve(__dirname, "TestLib.dll"));
lib.asyncFunction("int TestAdd(int a, int b)");

const { TestAdd } = lib.interface;

const testAdd = async (a, b) => {
    console.log("before dll called");
    const c = await TestAdd(a, b);
    console.log("after dll called");
    return c;
};

module.exports = { testAdd };

mocha test code (invoke very slow, causes timeout)


const assert = require("chai").assert;
const lib = require("../src");

describe("library test", function() {
    it("addTest test", async function() {
        this.timeout(10000);

        let res = await lib.testAdd(1, 2);
        assert.equal(res, 3, "first add failed");

        res = await lib.testAdd(2, 2);
        assert.equal(res, 4, "first add failed");
    });
});

jest test code (test ok, takes about 6-7 seconds on my computer)


const lib = require("../src");

test("testAdd test", async function() {
    let res = 0;
    res = await lib.testAdd(1, 2);
    expect(res).toEqual(3);
    res = await lib.testAdd(2, 2);
    expect(res).toEqual(4);
});

Thank you for your solutions~

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

1 participant