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

Use pvm file for faster startup #20

Closed
jeswr opened this issue Jan 5, 2023 · 11 comments
Closed

Use pvm file for faster startup #20

jeswr opened this issue Jan 5, 2023 · 11 comments

Comments

@jeswr
Copy link
Collaborator

jeswr commented Jan 5, 2023

No description provided.

@josd
Copy link
Contributor

josd commented Jan 5, 2023

The image is currently made with https://github.com/eyereasoner/eye/blob/master/install.sh line https://github.com/eyereasoner/eye/blob/master/install.sh#L34
The image is currently called in https://github.com/eyereasoner/eye/blob/master/eye.sh

@josd
Copy link
Contributor

josd commented Jan 5, 2023

For the native eye the difference is

$ time swipl -f eye.pl -g main -- --version
eye --version
EYE v23.0105.0024 josd
SWI-Prolog version 9.1.2-17-gcd86f975e
starting 262 [msec cputime] 264 [msec walltime]

real    0m0.269s
user    0m0.261s
sys     0m0.011s

versus

$ time eye --version
eye --version
EYE v23.0105.0024 josd
SWI-Prolog version 9.1.2-17-gcd86f975e
starting 37 [msec cputime] 34 [msec walltime]

real    0m0.041s
user    0m0.040s
sys     0m0.002s

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 5, 2023

What I am struggling with is trying to work out how to generate the .pvm file in the WASM version of SWIPL since those arguments are provided when you intialise the module. That is, at what point can I call Module.fs.writeFile('eye.pl', ...) in

import { SWIPLModule } from 'swipl-wasm/dist/common';
import { queryOnce, runQuery, SWIPL, writeEye } from '..';

(async () => {
  const Module : SWIPLModule= await SWIPL({ print: (s: string) => {
    console.log(s);
  }, arguments: ['-f', 'eye.pl', '-g', 'main', '--', '--version'] } as EmscriptenModule);

})();

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 5, 2023

ignore this: it should just be swipl -x, I write this when I was tired and not looking closely at the sample files.

I've gotten as far as #21 - where we can now run npm i and the end result is that eye.pvm gets built and then we generate the file lib/eye.pvm.ts.

@josd The problem that I am now encountering is that I don't really know what do do with this; in the example you give you're calling eye --version from the command line without SWIPL being involved at all now - but with the WASM version we can't really do that as far as I can tell; so how would I run the pvm file using the current SWIPL WASM tooling?

// cc @rla as you had useful insight into the previous issue we encountered related to this.

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 5, 2023

I've now tried

(async () => {
  const Module: SWIPLModule = await SWIPL({
    arguments: ['-x', './eye.pvm', '--', '"$@"'],
    preRun: (module: SWIPLModule) => {
      module.FS.writeFile('eye.pvm', fs.readFileSync(path.join(__dirname, '..', 'eye', 'eye.pvm')).toString());
    },
    print: console.log,
    printError: console.log
  });
})();

but it errors out with

[FATAL ERROR: at Fri Jan  6 10:51:30 2023
        Could not open resource database "./eye.pvm": Not a tty]
Aborted()

See #21 (comment) to reproduce locally

// cc @rla @JanWielemaker as it seems like it could be a problem with the swipl-wasm build rather than my usage of it

@jeswr jeswr mentioned this issue Jan 6, 2023
@JanWielemaker
Copy link

I don't know. Seems it cannot open eye.pvm and the reported errno is bogus.

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 7, 2023

Seems it cannot open eye.pvm and the reported errno is bogus.

As in failing to parse it? It is definitely finding the file because if I remove the step adding eye.pvm we get the (sensible) error

[FATAL ERROR: at Sat Jan  7 17:23:34 2023
        Could not open resource database "eye.pvm": No such file or directory]
Aborted()

@JanWielemaker
Copy link

Ok. Note that the eye.pvm is a zip file. If it is opened but unusable as resource file it is probably an invalid zip file according to the embedded minizip library.

@jeswr
Copy link
Collaborator Author

jeswr commented Jan 8, 2023

Ah - thanks for clarifying (in particular the fact that it is a zip)! I've fixed it; the problem was doing a .toString() call that tried to interpreted it as utf8. @JanWielemaker @josd are you able to tell me what encoding is normally using in .pvm files? I've tried to google around but it seems .pvm is used for a few different things so it is hard to find the right answer.

@jeswr jeswr closed this as completed Jan 8, 2023
@josd
Copy link
Contributor

josd commented Jan 8, 2023

.pvm is a swipl quick load format which we use to make the generic reasoning engine eye.pvm but also and esp. for specialized reasoning engines preloaded with large amounts of so called static .ttl data and .n3 rules.

@josd
Copy link
Contributor

josd commented Jan 8, 2023

Thank you so much @jeswr and @JanWielemaker, the eye initialization is now 5 times faster!

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

3 participants