Why is Graals AOT compiler slower than JIT?












2















In general, when developers try to explain why (highly tuned) C++ is about 2x faster than Java, they mention that one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT. So I assumed that the AOT compilation in Graal would have similar opportunities so that even if it's not as fast as C++, it would be at least faster than JIT compilation -- however, this does not seem to be the case. Why is that? In particular, are there specific scenarios where Graal's AOT compiler would be faster? And conversely, are there cases when JIT will be faster than GRAAL AOTr? (This way, I can make an informed decision as to how useful it might be once I fully built my solution)?










share|improve this question























  • "it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

    – Jorn Vernee
    Feb 17 at 21:07
















2















In general, when developers try to explain why (highly tuned) C++ is about 2x faster than Java, they mention that one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT. So I assumed that the AOT compilation in Graal would have similar opportunities so that even if it's not as fast as C++, it would be at least faster than JIT compilation -- however, this does not seem to be the case. Why is that? In particular, are there specific scenarios where Graal's AOT compiler would be faster? And conversely, are there cases when JIT will be faster than GRAAL AOTr? (This way, I can make an informed decision as to how useful it might be once I fully built my solution)?










share|improve this question























  • "it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

    – Jorn Vernee
    Feb 17 at 21:07














2












2








2


2






In general, when developers try to explain why (highly tuned) C++ is about 2x faster than Java, they mention that one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT. So I assumed that the AOT compilation in Graal would have similar opportunities so that even if it's not as fast as C++, it would be at least faster than JIT compilation -- however, this does not seem to be the case. Why is that? In particular, are there specific scenarios where Graal's AOT compiler would be faster? And conversely, are there cases when JIT will be faster than GRAAL AOTr? (This way, I can make an informed decision as to how useful it might be once I fully built my solution)?










share|improve this question














In general, when developers try to explain why (highly tuned) C++ is about 2x faster than Java, they mention that one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT. So I assumed that the AOT compilation in Graal would have similar opportunities so that even if it's not as fast as C++, it would be at least faster than JIT compilation -- however, this does not seem to be the case. Why is that? In particular, are there specific scenarios where Graal's AOT compiler would be faster? And conversely, are there cases when JIT will be faster than GRAAL AOTr? (This way, I can make an informed decision as to how useful it might be once I fully built my solution)?







graalvm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 18:33









Jonathan SylvesterJonathan Sylvester

423410




423410













  • "it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

    – Jorn Vernee
    Feb 17 at 21:07



















  • "it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

    – Jorn Vernee
    Feb 17 at 21:07

















"it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

– Jorn Vernee
Feb 17 at 21:07





"it would be at least faster than JIT compilation -- however, this does not seem to be the case.", would be great if you could provide your source for that.

– Jorn Vernee
Feb 17 at 21:07












1 Answer
1






active

oldest

votes


















1















one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT.




This is not really an issue. The JIT can take as long at optimizing as it wants, and do multiple incremental compilation runs as well. This can be done in a background thread.



What it really comes down to is: information. Highly tuned C++ is fast because the developer who wrote it used all the information available to optimize the code. This means being able to make more assumptions or do clever optimization tricks, and the C++ language allows you to tweak all the optimization knobs.



The JIT does it's best of course, but it doesn't necessarily have all the information about a particular piece of code that a developer would have, because it's a more general optimizer. For some cases the JIT also has compiler intrinsics, which are basically hand tuned replacements for certain methods and code patterns. Again, this is the developer taking advantage of superior knowledge about a certain situation to do optimizations.



However, with plain Java AOT it's really the opposite; Because the AOT compiler runs ahead of program execution, it has less information about the environment the program runs in, and no profiling information, and because of that it can do less good optimization.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011441%2fwhy-is-graals-aot-compiler-slower-than-jit%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1















    one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT.




    This is not really an issue. The JIT can take as long at optimizing as it wants, and do multiple incremental compilation runs as well. This can be done in a background thread.



    What it really comes down to is: information. Highly tuned C++ is fast because the developer who wrote it used all the information available to optimize the code. This means being able to make more assumptions or do clever optimization tricks, and the C++ language allows you to tweak all the optimization knobs.



    The JIT does it's best of course, but it doesn't necessarily have all the information about a particular piece of code that a developer would have, because it's a more general optimizer. For some cases the JIT also has compiler intrinsics, which are basically hand tuned replacements for certain methods and code patterns. Again, this is the developer taking advantage of superior knowledge about a certain situation to do optimizations.



    However, with plain Java AOT it's really the opposite; Because the AOT compiler runs ahead of program execution, it has less information about the environment the program runs in, and no profiling information, and because of that it can do less good optimization.






    share|improve this answer






























      1















      one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT.




      This is not really an issue. The JIT can take as long at optimizing as it wants, and do multiple incremental compilation runs as well. This can be done in a background thread.



      What it really comes down to is: information. Highly tuned C++ is fast because the developer who wrote it used all the information available to optimize the code. This means being able to make more assumptions or do clever optimization tricks, and the C++ language allows you to tweak all the optimization knobs.



      The JIT does it's best of course, but it doesn't necessarily have all the information about a particular piece of code that a developer would have, because it's a more general optimizer. For some cases the JIT also has compiler intrinsics, which are basically hand tuned replacements for certain methods and code patterns. Again, this is the developer taking advantage of superior knowledge about a certain situation to do optimizations.



      However, with plain Java AOT it's really the opposite; Because the AOT compiler runs ahead of program execution, it has less information about the environment the program runs in, and no profiling information, and because of that it can do less good optimization.






      share|improve this answer




























        1












        1








        1








        one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT.




        This is not really an issue. The JIT can take as long at optimizing as it wants, and do multiple incremental compilation runs as well. This can be done in a background thread.



        What it really comes down to is: information. Highly tuned C++ is fast because the developer who wrote it used all the information available to optimize the code. This means being able to make more assumptions or do clever optimization tricks, and the C++ language allows you to tweak all the optimization knobs.



        The JIT does it's best of course, but it doesn't necessarily have all the information about a particular piece of code that a developer would have, because it's a more general optimizer. For some cases the JIT also has compiler intrinsics, which are basically hand tuned replacements for certain methods and code patterns. Again, this is the developer taking advantage of superior knowledge about a certain situation to do optimizations.



        However, with plain Java AOT it's really the opposite; Because the AOT compiler runs ahead of program execution, it has less information about the environment the program runs in, and no profiling information, and because of that it can do less good optimization.






        share|improve this answer
















        one factor is that C++ AOT compilation has much more time to do extensive optimizations than JIT.




        This is not really an issue. The JIT can take as long at optimizing as it wants, and do multiple incremental compilation runs as well. This can be done in a background thread.



        What it really comes down to is: information. Highly tuned C++ is fast because the developer who wrote it used all the information available to optimize the code. This means being able to make more assumptions or do clever optimization tricks, and the C++ language allows you to tweak all the optimization knobs.



        The JIT does it's best of course, but it doesn't necessarily have all the information about a particular piece of code that a developer would have, because it's a more general optimizer. For some cases the JIT also has compiler intrinsics, which are basically hand tuned replacements for certain methods and code patterns. Again, this is the developer taking advantage of superior knowledge about a certain situation to do optimizations.



        However, with plain Java AOT it's really the opposite; Because the AOT compiler runs ahead of program execution, it has less information about the environment the program runs in, and no profiling information, and because of that it can do less good optimization.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 23 at 16:32

























        answered Feb 23 at 16:20









        Jorn VerneeJorn Vernee

        21k34064




        21k34064
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011441%2fwhy-is-graals-aot-compiler-slower-than-jit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith