Effective Scalaãå ¬éããã¦æ°æ¥çµã¡ã¾ããã Scalaã¯ãã¤ããªããè¨èªã¨è¨ãããã ããã£ã¦ãå½ä»¤åãé¢æ°åã®ã¹ã¿ã¤ã«ä¸¡æ¹å ±ã§æ¸ããã¨ããç´ æ´ããããæã£ã¦ãã¾ãã Scalaã«ã¯ãã¤ãã«ã¨ãããã¹ãæ¬ãããã¤ãåºã¦ãã¾ãããã®ä¸ã®ä¸ã¤ãâã Scalaã¹ã±ã¼ã©ãã«ããã°ã©ãã³ã°ç¬¬2ç ä½è : Martin Odersky,Lex Spoon,Bill Venners,ç¾½çç°æ ä¸,水島å®å¤ª,é·å°¾é«å¼åºç社/ã¡ã¼ã«ã¼: ã¤ã³ãã¬ã¹ã¸ã£ãã³çºå£²æ¥: 2011/09/27ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼è³¼å ¥: 4人 ã¯ãªãã¯: 109åãã®ååãå«ãããã° (28件) ãè¦ã ã³ã¬ãèªãã¨Scalaã§å®æ½ããããã®mustãªè¨æ³ã¯ç¥ããã¨ãã§ãã¾ãããã ãããããã¹ã(should)ã¨ãããããªãã¦ãã¦ãããè¨æ³ã¯åããã¾ããã Effective Scalaãèªãã¨Twitt
JVM ã«ãããæ§è½ JVM ã«ãããæ§è½ã¢ãã«ã¯è«è©ããã¯è²ã ããããããã«å·»ãè¾¼ã¾ãã¦çµå±ããç解ããã¦ãªãã¨è¨ããã æ§ã ãªçç±ãããããã³ã¼ãã¯æå¾ ããã¦ãããããæ§è½ãæªãã£ãããã¹ã±ã¼ã©ãã«ã§ã¯ãªãã£ããããã 以ä¸ã«ããã¤ãã®çç±ãã¿ã¦ããã ä¸ã¤ã¯ JVM ä¸ã®ã¢ããªã±ã¼ã·ã§ã³ã®ã³ã³ãã¤ã«å·¥ç¨ãéçã«ã³ã³ãã¤ã«ãããè¨èªã®ããã¨ã¯åãã§ã¯ãªãã¨ãããã¨ãæããããï¼[ 2 ] åç §ï¼ã Java 㨠Scala ã®ã³ã³ãã¤ã©ã¯ã½ã¼ã¹ã³ã¼ãã JVM ãã¤ãã³ã¼ãã«å¤æããã ãã§ãæé©åã¯ã»ã¨ãã©è¡ããªãã ç¾ä»£ç㪠JVM ã®å¤ãã§ã¯ããã°ã©ã ã®ãã¤ãã³ã¼ããå®è¡ãããã¨ãããã¯å®è¡ãã¦ãããã·ã³ã®ã³ã³ãã¥ã¼ã¿ã¢ã¼ããã¯ãã£ã®ãã·ã³ã³ã¼ãã«å¤æããã ããã¯ã¸ã£ã¹ãã¤ã³ã¿ã¤ã ã³ã³ãã¤ã© (just-in-time compilerãJITã³ã³ãã¤ã©) ã¨å¼ã°ããã ãããã
以åããã¤ã¯ããã³ããã¼ã¯ãã¼ã«ã§ããJMHã試ãã¦ã¿ãã¨ããã¨ã³ããªãæ¸ãã¾ããã JMH http://openjdk.java.net/projects/code-tools/jmh/ ãã¤ã¯ããã³ããã¼ã¯ãã¼ã«ãJMHã試ã http://d.hatena.ne.jp/Kazuhira/20140102/1388662362 ã§ããã®å¾Scalaã§æ¸ããã¨ãã¦ãAPTãããã®ã§Javaã®ããªãã¸ã³ã¼ããå¿ è¦ã ã¨ããã¨ã³ããªãæ¸ãã¾ããã Scalaï¼sbtã¨ãJMHãåããã¦ä½¿ã http://d.hatena.ne.jp/Kazuhira/20140102/1388671010 ããã«å¯¾ãã¦ãæè¿@xuwei_kããããsbtã®JMHãã©ã°ã¤ã³ãã§ããã¨ããã³ããããã ããã®ã§ã試ãã¦ã¿ããã¨ã«ãã¾ããã sbt-jmh ãã©ã°ã¤ã³ã®ååã¯ããsbt-jmhãã§ãã sbt-jm
"æ°ãã" ã¨ã¯ãä»ã¾ã§å ¨é¨ç¡åclassã«ã³ã³ãã¤ã«ãã¦ãã©ã ãããinvoke dynamic使ã£ã¦åçã«çæããããã«ãªãã¨ããããããã¤ã ã©ã ã以å¤ã®æé©åããã£ã¦ãããã§ããï¼è©³ããã¯ç¥ãã¾ããã Scala 2.12ããæ£å¼ã«å ¥ããããã§ããã(ããæ¸ãã¦ãæç¹ããè¦ã¦)ã¤ãæ¨æ¥ããã(2015/06/25)ã«åºãScala2.11.7ã§ããæ示çã«ãªãã·ã§ã³ãæå®ããã°ãå®é¨çãªãã·ã§ã³ã¨ãã¦ã§ããã使ããããã§ãã å é¨ã®ä»çµã¿ã¯ã以ä¸ã®Scaladays2015ã®ã¹ã©ã¤ãè¦ãã¨ãããã¨ã¯åèªã°ã°ã£ã¦ãã ãã http://downloads.typesafe.com/website/presentations/ScalaDaysSF2015/T2_Rytz_Backend_Optimizer.pdf å ¬å¼ã«æ¸ãã¦ããã¾ããã2.11.7ã«ããã¦Java8ã®ããã¯ã¨ã³ãã
[ã¾ã¨ã] LLè³ãscalaã®åå¼·ãå§ããã LLè³ãscalaã®åå¼·ãå§ããã ãã®34 Scalaã³ããæ¬ã®11ç« æ®ãããã£ã¦ãã¾ãã¾ããã¼ãä»åã¯ããªããã£ãåãªããã«ã¤ãã¦ãã¹ 11ç« ã¯å ¨ä½çã«åº§å¦çãªå 容ãªã®ã§ã»ã¼åçµâ¦(´ã»Ïã»ï½)â¦ã¾ãé å¼µãããããã ããªããã£ãåã®å®è£ æ¹æ³ Scalaã§ã®æ´æ°æ¼ç®ã¯JVMã¨ã®äºææ§ã®ç¹ããããªããã£ãåã®æ¼ç®ã¨ãã¦å®ç¾©ããã¦ãããããã¹ ãã ããæ´æ°ããªãã¸ã§ã¯ãã¨ãã¦æ±ãå¿ è¦ãã§ããå ´åã¯java.lang.Integerã¨ããããã¯ã¢ããã¯ã©ã¹ã使ãããããã¹ããã¡ãªã¿ã«æ´æ°ããªãã¸ã§ã¯ãã¨ãã¦æ±ãã®ã¯toStringã¡ã½ããã®å¼ã³åºããAnyåã®å¤æ°ã«æ´æ°ãä»£å ¥ãããããå ´åã¨ã®ãã¨ã§ãã ãã®ããã«Intåã®æ´æ°ã¯java.lang.Integerã«ééçã«å¤æããããããããã®å ´åã®java.lang.Integerãããã¯ã·
ã©ãã§ãããç´°ããããã©ã¼ãã³ã¹ã®è©±ãã¨ããã©ã¤ãã©ãªä½ã£ã¦éãã§ãå½±é¿ã§ãæè¿boxingãç´°ããããã©ã¼ãã³ã¹ã«ã¤ãã¦è²ã 調ã¹ã¦ãã®ã§ãã¤ãã§ã«æ¸ãã¦ããã 以åãããããã¡ãã£ã¨ã ãæ°ã«ãªã£ã¦ããã©ãã¡ããã¨è¨æ¸¬ãã¦ã¿ããä¸å¿å·®ãã§ãã ã¤ã¾ã val intList: List[Int] = // 大ããªIntã®List intList.map(identity) ããã val intList: List[Int] = // 大ããªIntã®List intList.map(x => x) ã®ã»ãããéããªã(å¯è½æ§ããã)ã¨ãã話ã§ãããã¡ãããæé©åã«ãã£ã¦å·®ãã§ãªããã¨ãããããå·®ãåºãã¨ãã¦ãããããæ°%ããæ°å%ç¨åº¦ã§ãããã scala -Xprint:jvm -e "List(0).map(identity)"ã scala -Xprint:jvm -e "List(
3. ⢠ãã®ã¹ã©ã¤ãã«åºã¦ããé度ãããã©ã¼ãã³ã¹ã¯ä¸¦åå®è¡ ãèæ ®ãã¦ãã¾ããã ⢠ãã®ã»ãã·ã§ã³ã¯Scalaãã®ãã¼ã対象ã¨ãã¦ãã¾ãã ⢠ãã³ããã¼ã¯ãåå¾ããç°å¢ã¯æ¬¡ãã¼ã¸ã«è¡¨ç¤ºãã¾ãã ⢠ããã©ã¼ãã³ã¹ã«ã¤ãã¦@Keenããããã¤ãã®ã¢ããã¤ã¹ã é ãã¾ããããããã¨ãï¼ acknowledgement ack. Parallel execution is not taken into account. 4. environment of benchmark ã¤ã³ã¹ã¿ã³ã¹ Amazon EC2 m3.2xlarge vCPU 8 memory 30GB ãã£ã¹ã¯ æ±ç¨SSD OS CentOS6.7-Final jdk jdk1.8.0u65(oracle, server vm) scala 2.11.7 ãã«ããã¼ã« sbt ãã³ããã¼ã¯ãã¼ã« sbt-jmh 0.2.
åæé èªä½ã¯ã¨ãã«æå³ããã¾ããããã¨ãã©ã®æé©åãã©ã®ãããéããªãã®ãï¼ãã詳細ã«è¨ã£ããã¨ã¯ãªãã§ããããåççã«ãããªã£ã¦ããã(ryãã¨ããã®ã説æããã«éãã¾ãããä¸ã«ã¯ãJITã§ç¡æå³ã«ãªããããªã©ãã§ãããç´°ãããããã¨ããæ¸ãã¦ããã¾ãããæé©åã®ãã¬ã¼ããªãã¨ãã¦å¤±ããã®ãããã®ã§ããã®ãããèªå·±è²¬ä»»ã§ãé¡ããã¾ããæ¬å½ã«æé©åãå¿ è¦ã¨ãããå ´åã¯ã以ä¸ã®ãã®ãç¡éã«å®è¡ããããã¾ãè¨æ¸¬ããã»ããããã®ã¯ãè¨ãã¾ã§ãããã¾ããã*1 1. private[this]ãã¤ãã scalaã®valãvarã¯ãprivate[this]ã«ããã¨ãã®ã¿ãç´æ¥ã®ãã£ã¼ã«ãã¢ã¯ã»ã¹ã«ãªãã¾ã(ãã以å¤ã§ã¯ã¡ã½ããå¼ã³åºã)ãã·ã³ã°ã«ãã³ã®objectã®å ´åãåæ§ã§ããprivate[this]ãã¤ããããå ´åã¯ã§ããã ãã¤ãã¾ããã 2. ãªãã§ãããã§ãListãã¤ãã㪠æåã®
åæ(æ稿æ¥ï¼2011/11/30)ã¸ã®ãªã³ã¯ Yammerã®å¾æ¥å¡ã§ããCoda Haleæ°ãScalaã®åç¨ãã³ãã§ããTypesafe社ã¸éã£ãã¡ã¼ã«ãYCombinatorã¨GitHubã®gistçµç±ã§ãªã¼ã¯ãããã¡ã¼ã«ã«ããã°ãYammerã¯è¤éããæ§è½é¢ãéã¿ã¦ãåºç¤ã®ã¤ã³ãã©ãScalaããJavaã¸æ»ãããã ã Yammerã®PRé¨éã®Shelley Riskæ°ã«ããã°ãã®ã¡ã¼ã«ã¯Coda Haleæ°ã®å人çãªæè¦ã§ãããYammerã®å ¬å¼ãªè¦è§£ã§ã¯ãªãã¨ã®ãã¨ã ããã®ãªã¼ã¯å¾ãCoda Haleæ°ã¯èªèº«ã®èããhttp://codahale.com/the-rest-of-the-story/ã§è¡¨æãã¦ãããæ°ã¯ãã®ã¡ã¼ã«ã¯Donald Fischeræ°(Typesafe社ã®CEO)ããã®ãã£ã¼ãããã¯ã®è¦è«ã«çãããã®ã§ã移è¡ã示åãããã¤ã¼ããè£è¶³ãããã®ã ã¨èª¬æãã¦
ãµã¤ãã¼ã¨ã¼ã¸ã§ã³ãã®ã¤ã³ã¿ã¼ãããåºåäºæ¥ãæè¡é¢ããæ¯ãããã¢ããã¯ã¹ã¿ã¸ãªãã§ã¯ãé¢æ°åè¨èªã®ä¸ã¤ã§ããScalaãç©æ¥µçã«æ´»ç¨ããã¦ãã¾ããä»åãã¹ãã¼ããã©ã³ç¹ååã®ãªã¢ã«ã¿ã¤ã ã¿ã¼ã²ãã£ã³ã°åºåãå®ç¾ãããµã¼ãã¹ãDynalystãï¼â å³1ï¼ãéçºããéç¿å æ°ï¼åç1â ï¼â ãããã¦ã¹ãã¼ããã©ã³åãã¢ããã©ãããã©ã¼ã ã§ãããAMoAdã¢ããããã¯ã¼ã¯ãï¼â å³2ï¼ã®éçºã¨éç¨ãæ å½ããäºä¸ããæ°ï¼åç2ï¼ã«ãScalaã®é åã伺ãã¾ããã ææ°ã®ã¢ããã¯ãè©°ãè¾¼ãã Dynalystã«Scalaãæ¡ç¨ ââæåã«Scalaã«èå³ãæã£ããã£ãããæãã¦ãã ããã äºä¸ï¼ãµã¤ãã¼ã¨ã¼ã¸ã§ã³ãã«å ¥ç¤¾ããåããé¢æ°åè¨èªã«èå³ããããè©ä¾¡ãå¿ è¦ã«ãªãã¾ã§å®éã®è¨ç®ãè¡ããªãé 延è©ä¾¡ã®ããã¿ãªã©ã«é åãæãã¦ãã¾ããããã®ä¸ã§ãç¹ã«Scalaã«ã¯JVMä¸ã§å®è¡ã§ããã¨ãã£ãã¡ãªããããã
jstack ã¨ãããã¼ã«ãããããã®ãã¼ã«ã¯ãç¾å¨å®è¡ä¸ã® Java ããã»ã¹ã®ã¹ã¬ããã®ç¶æ ãåå¾åºæ¥ããã¼ã«ã ã æã£ãããã«æ§è½ãåºãªãæããããããã¯ã£ã½ãç¾è±¡ãçºçããéã¯ãã®ãã¼ã«ã使ã£ã¦ã¹ã¬ããã®ç¶æ ãåå¾ãã¤ã¾ãã¹ã¬ãããã³ããå¾ã¦ããããã解決ã®ç³¸å£ãæ¢ãã ä»åã®ãµã³ãã«ã³ã¼ãã¯ä¸è¨ã³ã¼ãã å°ãé·ãããThread1 㨠Thread2 ã¯ã©ã¹ã¯ã»ã¼åä¸ã ãéãã®ã¯ããªã½ã¼ã¹ãããã¯ããé åºãThread1 ã¯ã©ã¹ã¯ resource1, resource2 ã®é ã«ããã¯ããããThread2 ã¯ã©ã¹ã¯ resource2, resource1 ã®é ã«ããã¯ãããã¤ã¾ãããããï¼ã¤ã®ã¯ã©ã¹ãåæã«å®è¡ããã¨ãããããã¯ãèµ·ããã public class DeadLockTest { public static Object resource1 = new Obje
ã¿ã¹ã¯ãµãã¼ã 並åã³ã¬ã¯ã·ã§ã³ã¯ãæ¼ç®ã®ã¹ã±ã¸ã¥ã¼ãªã³ã°ã«é¢ãã¦ã¢ã¸ã¥ã¼ã«åããã¦ããã å ¨ã¦ã®ä¸¦åã³ã¬ã¯ã·ã§ã³ã¯ã¿ã¹ã¯ãµãã¼ãã¨ãããªãã¸ã§ã¯ãã«ãããã©ã¡ã¼ã¿åããã¦ããããããã¿ã¹ã¯ã®ã¹ã±ã¸ã¥ã¼ãªã³ã°ã¨ããã»ããµã¸ã®è² è·åæ£ (load balancing) ãæ å½ããã ã¿ã¹ã¯ãµãã¼ãã¯å é¨ã«ã¹ã¬ãããã¼ã«ã®å®è£ ã¸ã®åç §ãæã£ã¦ãããã¿ã¹ã¯ãããå°ããã¿ã¹ã¯ã«ãã¤ã©ã®ããã«åå²ãããã決å®ãã¦ããã ãã®å é¨ã®æ¯ãèãã«é¢ãã¦ãã詳ããç¥ãããå ´åã¯ãã®ãã¯ããã¸ã¼ã¬ãã¼ããåç §ãã¦ã»ãã [ 1 ]ã ç¾è¡ã®ä¸¦åã³ã¬ã¯ã·ã§ã³ã«ã¯ããã¤ãã®ã¿ã¹ã¯ãµãã¼ãã®å®è£ ãããã JVM 1.6 以ä¸ã§ããã©ã«ãã§ä½¿ãããã®ã¯ã ForkJoinTaskSupport ã§ãããã¯å é¨ã§ãã©ã¼ã¯/ã¸ã§ã¤ã³ãã¼ã«ã使ãã JVM 1.5 ã¨ãã®ä»ã®ãã©ã¼ã¯/ã¸ã§ã¤ã³ãã¼ã«ããµãã¼ãããªã JVM
Scalaã®ä¸¦è¡å¦çã¨ã¢ã¯ã¿ã¼ã並åã³ã¬ã¯ã·ã§ã³ï¼ã¹ã±ã¼ã©ãã«ã§é¢æ°åã§ãªãã¸ã§ã¯ãæåãªScalaå ¥éï¼10ï¼ï¼1/3 ãã¼ã¸ï¼ ååã®ããããã¨ä»åã®å 容 ååã®è¨äºãScalaã®æ½è±¡åã¨æé»ã®åå¤æï¼å¼æ°ããã©ã¡ã¼ã¿å¶ç´ãã§ã¯ããimplicitããã¼ã¯ã¼ãã使ç¨ããæé»ã®åå¤æã¨æé»ã®ãã©ã¡ã¼ã¿ãªã©ãç´¹ä»ãã¾ããã ä»åã¯Scalaãæ¨æºã§æã£ã¦ãã並è¡å¦çç¨ã©ã¤ãã©ãªã¨ä¸¦åã³ã¬ã¯ã·ã§ã³ãç´¹ä»ãã¾ãã 第1åè¨äºã§ã¯ãScalaæ¨æºã®REPLã¨Scala IDEã§åä½ã確èªãã¦ã¿ã¾ãããä»å¾æ¬è¨äºã®ãµã³ãã«ã³ã¼ãã¯ãã©ã¡ãã§ç¢ºèªãã¦ãåé¡ã¯ããã¾ãããã対話çã«å®è¡ã§ãã1æãã¨ã«ã³ã¼ãã®çµæãåãã£ã¦ä¾¿å©ãªã®ã§ãåºæ¬çã«ã¯REPLãç¨ãã¦èª¬æãã¦ããã¾ãã Scala IDEã使ç¨ããå ´åã第1åè¨äºã®ãScala IDE for Eclipseã§ãHello Scalaï¼ããã
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}