Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Does graalvm help us? #22

Closed
thekalinga opened this issue Apr 25, 2018 · 5 comments
Closed

Does graalvm help us? #22

thekalinga opened this issue Apr 25, 2018 · 5 comments

Comments

@thekalinga
Copy link

thekalinga commented Apr 25, 2018

I just came across graalvm & wanted to check whether graalvm can make our life simpler & improve performance when doing pre-rendering?

http://www.graalvm.org/

Thanks

@thekalinga thekalinga changed the title Does graalvm help with this? Does graalvm help us? Apr 25, 2018
@swaechter
Copy link
Owner

Hey. Indeed GraalVM looks like a really interesting alternative (Although it's a separate JVM) I used this code for testing:

server.ts:

import {RenderAdapter} from "./renderadapter";

const {AppServerModuleNgFactory, LAZY_MODULE_MAP} = require("./../dist-server/main.bundle");

var renderAdapter = new RenderAdapter(AppServerModuleNgFactory, LAZY_MODULE_MAP, "<app-root></app-root>");
renderAdapter.renderPage("uuid1", "/");
renderAdapter.renderPage("uuid2", "/home");
renderAdapter.renderPage("uuid3", "/keywords");
renderAdapter.renderPage("uuid4", "/about");

renderadapter.ts:

require("zone.js/dist/zone-node");

import {provideModuleMap} from "@nguniversal/module-map-ngfactory-loader";
import {renderModuleFactory} from "@angular/platform-server";

export declare function registerRenderAdapter(renderadapter: RenderAdapter): void;

export declare function receiveRenderedPage(uuid: string, html: string, error: any): void;

export class RenderAdapter {

    constructor(private appservermodulengfactory: any, private lazymodulemap: any, private html: string) {
        //registerRenderAdapter(this);
    }

    setHtml(html: string) {
        this.html = html;
    }

    renderPage(uuid: string, uri: string) {
        renderModuleFactory(this.appservermodulengfactory, {
            document: this.html,
            url: uri,
            extraProviders: [
                provideModuleMap(this.lazymodulemap)
            ]
        }).then(html => {
            console.log(uuid + ": " + html);
            //receiveRenderedPage(uuid, html, null);
        });
    }
}

I am able to render these requests with the node binary provided by GraalVM (I guess they just deploy a copy of Node with some Graal related changes)

Launching the server.js from Java like seen here does not work. I get an error message that require is undefined or the Node modules can't be found.

At the moment I am not sure if I have to rebuild Graal.js or if it is not supported at all. I will open an issue for this in the GraalVM project.

@thekalinga
Copy link
Author

Thanks. Please link that issue here

@swaechter
Copy link
Owner

@thekalinga I just posted my question: oracle/graaljs#2

@divyakumarjain
Copy link

divyakumarjain commented May 12, 2018

@swaechter Seems like https://github.com/graalvm/examples/blob/master/weather_predictor/weatherServer.js javascript in https://github.com/graalvm/examples uses "require".

Did some additional research and seems like nodejs "require" aka module is available when application is started as nodejs application. When Java application triggers Javascript it does not have nodejs feature but can only trigger Javascript interpreter which does not have nodejs capabilities.

@swaechter
Copy link
Owner

swaechter commented May 28, 2018

@divyakumarjain Yeah, I also saw the example.

Did some additional research and seems like nodejs "require" aka module is available when application is started as nodejs application. When Java application triggers Javascript it does not have nodejs feature but can only trigger Javascript interpreter which does not have nodejs capabilities.

Yes, that's true. As Christian pointed out in the GraalVM issue, it's a lot easier to implement a custom JS engine into Node.js than Node.js capabilities into Java.

For now I am going to close this issue, because it's also quite a burden to use a custom JVM. I am looking for a really cool draft in #23

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants