Académique Documents
Professionnel Documents
Culture Documents
Searchforpeople,placesandthings
TheHipHopVirtualMachine
byJasonEvansforFacebookEngineering(Notes)onFriday,December9,2011at2:00pm
Tagged
We'realwayslookingforwaystomakeourcomputinginfrastructuremore efficient,andin2010wedeployedHipHopforPHPtohelpsupportthegrowing numberofFacebookusers.WhileHipHophashelpedusmakesignificantgains intheperformanceofourcode,itsrelianceonstaticcompilationmakes optimizingourcodetimeconsuming.Wewerealsocompelledtodevelopa separateHipHopinterpreter(hphpi)thatrequiresalotofefforttomaintain.So, earlylastyear,weputtogetherasmallteamtoexperimentwithdynamic translationofPHPcodeintonativemachinecode.WhatresultedisanewPHP executionenginebasedontheHipHoplanguageruntimethatwecalltheHipHopVirtualMachine(hhvm). We'reexcitedtoreportthatFacebookisnowusinghhvmasafasterreplacementforhphpi,withplansto eventuallyusehhvmforallPHPexecution. Facebookuseshphpi(andnowhhvm)fordaytodaysoftwaredevelopment,butusestheHipHopcompiler (hphpc)tocreateoptimizedbinariesthatservetheFacebookwebsite.hphpcisinessenceatraditional staticcompilerthatconvertsPHPASTC++x64.Wehavelongbeenkeenlyawareofthelimitations tostaticanalysisimposedbysuchadynamiclanguageasPHP,nottomentiontherisksinherentin developingsoftwarewithhphpianddeployingwithhphpc.Ourexperienceswithhphpcledustostart experimentingwithdynamictranslationtonativemachinecode,alsoknownasjustintime(JIT) compilation.Adynamictranslatorcanobservedatatypesastheprogramexecutes,andgeneratetype specializedmachinecode.Unfortunatelywedidn'thaveacleanmodelofPHPlanguagesemanticsbuilt intoHipHop,ashphpcandhphpiarebaseddirectlyontwodistinctabstractsyntaxtree(AST) implementations,ratherthansharingaunifiedintermediaterepresentation.Thereforewedevelopedahigh levelstackbasedvirtualmachinespecificallytailoredtoPHPthatexecutesHipHopbytecode(HHBC). hhvmuseshphpc'sPHPASTimplementationandextendsthepipelinetoPHPASTHHBC.We iterativelycodevelopedbothaninterpreterandadynamicHHBCx64translatorthatseamlessly interoperate,withtheprimarygoalofcleanlysupportingtranslation. Throughoutthehhvmprojectwehavetendedtowardsimplesolutions.Thisisnowheremoreevidentthan inthecorepremiseofthedynamictranslatoritself.MostexistingsystemsusemethodatatimeJIT compilation(e.g.,JavaandC#),thoughtracebasedtranslationhasalsobeenexploredinrecentsystems (e.g.,TamarinandTraceMonkey).Wedecidedtotryaverysimpleformoftracingthatlimitseachtraceto asinglebasicblockwithknowninputtypes.This"tracelet"approachsimplifiesthetracecache managementproblem,becausecomplexapplicationcontrolflowcannotcreateacombinatorialexplosionof traces.Eachtracelethasasimplethreepartstructure: Typeguard(s) Body Linkagetosubsequenttracelet(s)
Chat(3)
Andrologix Don'tForgettoLikeMe!
https://www.facebook.com/note.php?note_id=10150415177928920
1/5
6/19/13
Traceletsinducedbyf($a,42)andf($a,"hello") Howwelldoeshhvmwork?Ascomparedtohphpi,thehhvmbytecodeinterpreterisapproximately1.6X fasterforasetofrealworldFacebookspecificbenchmarks.Rightnowthereisastabilitygapbetweenthe hhvminterpreterandtranslator,whichprecludesusreportingtranslatorperformanceforthesamesetof benchmarks.However,wecaninferfromasetofbenchmarksbasedontheLanguageShootoutthat translatorperformanceisclosertohphpccompiledprogramperformancethantointerpreterperformance, asindicatedbythegeometricmeanofthebenchmarks(rightmostcolumninthefollowingfigure).The interpretersareallroughly0.2Xasfastashphpc,andthetranslatorisapproximately0.6Xasfast.For perspectiveonwhythismatters,considerthatmanyFacebookengineersspendtheirdaysdeveloping PHPcodeinanendlesseditreloaddebugcycle.Thedifferencebetween8secondand5secondreloads duetoswitchingfromhphpitothehhvminterpretermakesabigdifferencetoproductivity,andthis improvementwillbeevenmoredramaticonceweenablethetranslator.
https://www.facebook.com/note.php?note_id=10150415177928920
2/5
6/19/13
Weexpecthhvmtorapidlyclosetheperformancegapwithhphpccompiledbinariesoverthecoming monthsasthedynamictranslatorstabilizesandmatures.Infact,wepredictthathhvmwilleventually outperformstaticallycompiledbinariesinFacebook'sproductionenvironment,inpartbecauseweare alreadysharingenoughinfrastructurewiththestaticcompilerthatwewillsoonbeabletoleveragestatic analysisresultsduringtraceletcreation. Manychallengesremain,aswellassomeuncertaintyregardingthetranslator'sbehaviorwhenrunningthe entiretyofFacebook'sPHPcodebase.Intheneartermweneedtostabilizethetranslatorandcreatean ondiskbytecodeformat(toreducestartuptimeandtostoreglobalstaticanalysisresults).Thenwewill needtooptimize/tuneboththetranslatorandtheinterpreterasweobservehowthesystembehavesunder productionworkloads.Herearejustacoupleoftheinterestingproblemswewillsoonface: Thex64machinecodethatthetranslatorgeneratesconsumesapproximatelytentimesasmuch memoryasthecorrespondingHHBC.CPUinstructioncachemissesarealimitingfactorforthelarge PHPapplicationsthatFacebookruns,soahybridbetweeninterpretationandtranslationmay outperformpuretranslation. Thetranslatorcurrentlymakesnouseofprofilefeedback,thoughwedohavesamplebasedprofiling infrastructureinplace.Profileguidedoptimizationisanespeciallyinterestingproblemforusbecause Facebookdynamicallyreconfiguresitswebsitebetweencodepushes.Hotcodepathsmutateover time,andportionsofthex64translationcacheeffectivelybecomegarbage.Onesolutionmaybeto repeatedlycreateanewtranslationcachebasedonthepreviousone,takingadvantageofrecent profiledata.Thisapproachhasalotincommonwithsemispacegarbagecollection. Thefirst90%ofthehhvmprojectisdonenowwe'reontothesecond90%aswemakeitreallyshine.The hhvmcodeisdeeplyintegratedwiththeHipHopsourcecode,andwewillcontinuetoshareHipHopviathe publicGitHubsiteforHipHop,justaswehavesinceHipHop'sinitialreleaseinearly2010.Wehopethat thePHPcommunitywillfindhhvmusefulasitmaturesandengagewithustobroadenitsusefulness throughtechnicaldiscussions,bugreports,andcodecontributions.WeactivelymonitortheGitHubsite andmailinglist. JasonEvansisasoftwareengineerontheHipHopteamatFacebook,oneofnearly20peoplewhohave contributedtothehhvmprojectsofar. AdditionalHipHoparticles MoveFast(originalannouncement) Sixmonthslater(retrospectivesixmonthsafterrelease) MoreOptimizationsforEfficientServers MakingHPHPiFaster
LikeCommentShare
382
https://www.facebook.com/note.php?note_id=10150415177928920
3/5
6/19/13
1,370peoplelikethis. Viewpreviouscomments FanRobbinNiceWork.WillHHVMputonGitHub? December14,2011at1:12amLike 3
41of145
PeterPetermannijustwishthegithubpagewouldgetabitmoredocumentationlove. December14,2011at11:06amLike 1
NarimanAbdullayevIthinkthisthemostneededfeatureforphp.itwillmakephpmorecompetitivein comparisonwithotherlanguages.andmaysometimeitwillcompetewithJVM... December21,2011at3:16amLike 1 CoryCharlieIhavenocluewhatuguysaredoinitsalientomelol,butawesomejobsguys December21,2011at7:45pmLike VincensiusAgustinust onlyPHP? December22,2011at11:22pmLike THX December25,2011at10:18pmLike 1 3 1
IngusNeilandshmm,nowweneedpracticalimplementationonDebianbasedOSfortests December27,2011at7:17amLike 2
WayneRenbjorIsoneedtostartusingthisatwork.... January1,2012at11:07amLike 1
TonderaiWatsonZvidzwasothisgonemakeproducersgood,loanforstudio. January3,2012at5:50amLike 1
LuisVegaso$hitandreturn$hitanddump($hit).niceeasteregg. February9,2012at1:13pmLike 3
JonSnellIsthisprojectdead?Therehaven'tbeenanycommitstogithubin4months. April16,2012at2:10pmLike 2
RishavRastoginocommitsfor4months,hardlyanyrepliesonthegooglegroups..idon'tthinkthereismuch dev/supportgoingonfortheproject
https://www.facebook.com/note.php?note_id=10150415177928920
4/5
6/19/13
May3,2012at3:18amLike 1
AngeloDangelocanyouprovideabinaresversions.icantfindthem.compilertranslator,andserver May7,2012at7:25pmLike 1
AngeloDangelowellandphpscriptandresultingcbinaries May7,2012at7:25pmLike 1
InezKorczyskiSo..what'supwithHHVM,isitgoingtobereleasedanytimesoon? July27,2012at7:34pmLike 1
August18,2012at7:40pmLike
DenisTruffaut TechdiscussionswithHipHop/HHVMteam...righthere: http://www.facebook.com/pages/HipHopforPHP/282425744325 September26,2012at9:23amLike 1 HiroakiArakawa SeeTranslation November8,2012at1:04amLike LeeJack SeeTranslation January30at7:59amLike
NagaRajanhellosir:plsreadFacebookapplicationdevelopersintheapplicationsuser'scanbeusingmore "hi"word...everyonecansayasperday100andmoreso..Toadvancetechnologycanbeusedtodevelop on"icons"forHILabelorBatten.plsreferandVoteForMe...Thankingu March10at7:25pmLike TimoWitteToallthosepeoplebashingphp/sayingthatJavawouldbebetter.Iagreewithyouinsomeway. PHPismadeupofpartsthatdont"match",theyuseobjectshereandfunctionsthere,theorderofthe parametersdonthaveanysystembehindthem(look... SeeMore April10at4:56amLike 1 NadirConstantine June10at6:30amLike AngelLeondidyouexplorethepossibilityofseeingifjemallocwouldmaketheJavaVirtualMachinehandle memoryallocationbetterandinsteadcreateaPHPtoJavaByteCodecompilerthatwouldrunonajemalloc poweredversionoftheJavaVirtualMachine? Wh... SeeMore June11at2:05pmLike DavidYangnicearticleaboutHipHopVirtualMachine. June15at1:00pmLike LiDingwow.Waytogo. Sundayat11:16pmLike Writeacomment...
PressEntertopost.
hiphopalgiyrya
About
CreateAd
CreatePage
Developers
Careers
Privacy
Cookies
Terms
Help
Facebook2013English(US)
https://www.facebook.com/note.php?note_id=10150415177928920
5/5