Scale By The Bay 2018: Petr Zapletal, Adopting GraalVM
Recording: Scale By The Bay 2018: Petr Zapletal, Adopting GraalVM
you so goodbye everybody my name is Peter and I work for Disney streaming services you know we are not as cool as Pixar or Marvel or anything like that you know and also I have like nothing to do with Star Wars so if you want to ask me like how lightsabers work or something like that I will not be able to answer that but we do interesting stuff as well we are working on the platform which enables us to deliver like real-time streaming data to like thousands of thousands of users across the world and as you would assume a significant part of this is build you sink JVM and Scala and all these things I now the topic of this talk I dropped in growl DM growl is a new platform developed by Oracle it includes a new compiler and run time and some icater things which I'm gonna like mention later this project has been around for a while but a couple of months ago it started to like know like promising project to let's try this so I decided to check it out and I would like to share my findings with you lastly before we go on I like to say I have like no affiliation or I go or anything like that so there are multiple reasons why they decided to write a new compiler /vm from scratch and I think the main one was that one of the one of the compilers see to reach the end of its life cycle it is very difficult to do any bigger changes they're actually very little was done that in in the last few years it is like fight old code Britain and some like a city bus pass dialect and you know they're like very few people who like really understand how it works like c2 was an extremely successful piece of code but it's time to move on sooo growl around programs faster anywhere that's the official slogan and I bet it makes sense what is really good as that growl is is written in Java using the new JVM come power interface or JVM CI of course it is not as cool as it was written in Scala but it has like a lot of advantages like much more entry barrier for engineers Udrih like thousand of smudge of a developer's sound apart from that it also provides you know inbuilt memory safety and all these like java java traits last it's performance I think like a lot of people may be worried about Java jealous performance and like potential overhead but Joe is quite quite decent these days you know these twenty years of development you know brought some fruits so I don't think we need to I worry about this too much and as you can see in the picture growl the M is supposed to be a platform for different languages and environments and this dog I go for topics which I found the most interesting for us but before we do that I think it's important to discuss licensing Grall is available in community and enterprise versions and the enterprise version is like strictly better you know it's faster more performant has more features and things like that but if you want to use it and in production you have to pay for that that's how it works these days okay and that's what said and now what's the group at how grounded can help us with with compiling you know it's compiling and Scala so I think that star makes total sense actually I wanted to do the old why a skylight compiler so slow joke but if you look at the results which I got from my browser it doesn't look you know too bad for Scala which was quite surprising for me but anyway I think we all agree we would like to beat up our compiles and gravettian can like help us with that so if you are using SBT and want to start if single you just need to reference a codec I like this and toss these flags as you can see it is still marked as experimental so you know what set up the expectations correctly about the archive grout is a part of JDK since since version 10 so in that case you can just use the flags or you can use dedicated grad ground archive directly this archive is based on jerrican 8 and this may be actually easier for you because making your scalloped project compiling with JDK or even JDK 11 may be quite interesting exercise I think for starters the the easiest way is to head the flags and digital home path to your SVT herbs and for your java home I would recommend using the ground archive directory so you want to make it as simple as possible if you decide to go with JDK 11 you need to use Scout to the 13 and this might be a little bit challenging mostly because of limited library support scouting maintains the list of available libraries I have the link in a reference slide and the end alternatively you can use scottex which is the index of scala libraries and you can search it by by target version which is by hand in this case either way you should definitely check libraries before I commit think more time into it I tried it on one of our project you know to be honest quite a new one and I took like an hour to to make it work you can also expect some glitches on the roads like disabling some optimizations and things like that but like it should be fairly doable of course this very depends on your particular project I never promised comparison this bama this benchmark was run by a virgin who works for barranco as you can see there is a significant speed up and you know I have the link to his article and in the end as well you know I definitely recommend through it but like honestly I I was like very more interested and how it looks like you know in my in my projects so what are you compiling here it's a quite a decent project basically a banjo micro-services written scarf gross the code itself is function we are using libraries like play HTTP cats and its effect library to be add and many others and I'm very happy to say that you were able to see consistently better compile times using rel the speed ups around 10 percent are fatalistic which is very good so that was compiling and now let's see how can how we can use growl as as a JIT compiler for for runtime but before we do that let's have a super quick recap regarding just-in-time and ahead of time compilation traditional JVM uses jet or sometimes called dynamic compilation you know it has certain advantages the compiler can work with runtime information and also I perform aggressive optimizations and also ID optimize if needed and all these things on the other hand we have ahead of time compilation basically everything is compounds directly before the execution itself obviously it has very much channel resources when doing this in Israel like this was like not very common for JVM IOT using grabbed by the variables added and JDK 9 I believe but I don't think it was like widely adopted so if you want to use growl as a as a JIT compiler you need to run your binaries with you know these fights of course but before we dig into a little let's take a look at this it is a super simple algorithm for getting brands which I plan to use for violence access is later as you can see it just generates a stream of numbers which are filtered by a dysfunction again like no rocket science like it's it's quite functional but that was the only environment and everything is limited to the max constant this is going to be different for various exercises I plan to show you here and lastly as as you can see I not even you know using the results so it is like really let's warm up my CPU type of thing so I tried that using these two distributions and as you can see the numbers are slightly different than that we would hope for so what went wrong like of course like the test is nonsense you know we cannot measure performance like that you know I know sex but you guys to start like booing me immediately but anyway we need to take courage like slightly differently so take a look at Prime's version two from the functional perspective it does exactly the same thing you know I just remove the stuff stuff around a little bit and skip some lines you know mostly because like slides are like not big enough but I also added jmh annotations so we can test it a little bit more right seriously and as you can see the results are quite different now if you look at it it looks like real well like of course you may be wondering what about our unreal services so as you expect wisten pile of time testing because we are providing real time content and we can't just like start breaking things we tried a small subset of our services in our QA environments we sing RAL and it looks quite decent but you know I think we need to like dig a little bit deeper before we push it forward Gras is a project and it's early stages but they're already production opponents like like Twitter and that's it I have not found anyone else if you guys know about someone or add me oh please as I briefly mentioned before we have a OT available since JDK 9 but it was based on on an older version of growl but but the project I wanted to like show you here now is like way more ambitious it is called substrate vm and it basically allows you to compile jvn apps to do native code without any dependencies or on the only JVM so you will you really get a single static link executable out of it which is pretty cool to do so you just need to take your jars or class class files or whatever and use native image binary trees shipped way with growl and this may be quite an elegant way how we can solve some typical Julian shortcomings like sword starts or message arts or things like that pseudo crimes again this time I'll over the max to eight so we are really measuring just startups as you can see the difference is a huge I I would say as expected to be honest you know it works very very differently I was also wondering what happens if I move the max to something like 100,000 or something like that because in theory just should usually outperform äôt and volcanic benchmarks but I got this incorrect memory access it happened because JVM and substrate VM use different object layouts so memory offsets calculated to any compilations but incorrect you know this is like bad documented and it is like not too hard to fix but like that's not my point here my point here is to show you that you can't just take like any any program and execute it natively it cannot work like that there can be some refactoring work involved and some things I maybe like solvable at all as you guys would suspect substrate lien has certain limitations you know usually given by it's a only purpose and by the effort to keep it like small and concise so for example it is not possible to dynamically load gases because decompression works with a closed world assumption also like invokedynamic is very limited for for the same reason similar classes or fields you know things accessible via reflection must be known ahead of time or JVM tij and acts and like other native interfaces you know this management / debugging api's requires access to Gela bytecode which is like no longer available time yeah and so on I have I have a fader linked to the corresponding substrate VM page and the frenzy section and I will definitely recommend like going through it so like you won't get surprised later and now some use cases like obviously the most common use cases are like small programs or scripts you know anything you want to start up quickly and you don't expect to run it for longer time period I know also things like I like saps for example without the annoying you yeah okay you have Java slash skull AWS on down without their airing call starts there is an excellent article about this you know how to make this work you sing you go runtime it's also like in the new references section I really commend like going through it I'm not saying like it's like super useful but it's like definitely super interesting I think the question here s and like no just for the wonder thing but like for the majority of the use cases I mentioned do you want to use Scala in these cases I don't want to like start a religious war here so I live it up to you but you know like thing about that so we remember the topics I found the most interesting but growl offers offers more like often focused on boy good programming and as we are at scale by the bay I think max like sense to like go through it really quick you may leave you may like truffle which is a language implementation framework basically when you define your language using truffle it will use growl as a JIT compiler for folder language growl already has implementations for JavaScript Ruby are and piping you know and we'll likely see we will likely see more implementations in the future the languages in growl VM can like work together there is an API which lets you run code from one language and other one this lets you write you know true political programs and also you can take advantage of come on to link you know among these languages and you know things like that nope personally I believe that from a long-term perspective like this maybe growls I just I didn't tell you and then we have song which is a lrvm beta code interpreter you know using song you can on languages which can be transferred to LLVM bit code you know I see past past for example you know I'm saying others on the ground another interesting component is Emma ii which basic herbs you to run a growl BN in the oracle database so so for example you are able to run the same validation function and front-end and also in the database which is which is like nice but you know it's also a girl event dog anyway as you can see the original moto run programs faster anywhere makes quite a lot of sense here I know the summary girl has many promising features and according to my opinion it has massive potential but it's like a still bleeding edge technology but I think it's like Worf giving it a shot thank you [Applause] [Music] I think start to the 13.8% or vice-versa people to music and I think unit last article 13 right Oh [Music] yes he likes parties to the 13 I think [Music] yeah I'm thinking I'm some debate about I am British you guys if I didn't well because like if you want to go for 213 you basically are forced to use like milestones released and dead Sam I'm version for them and no just for scale but also like for Europe for all I right city much so there's like five risky to be honest