Movatterモバイル変換


[0]ホーム

URL:


fsc の速いクライアントを Ruby で書いた01:54

Posted at 2010/01/02 01:54, Modified at 2010/01/02 11:10

Scala にはfsc というクライアント・サーバ方式のコンパイラがある。コンパイラをサーバとして起動させたままにすることで、コンパイル時間の短縮を目指すらしい。

% time fsc A.scalafsc A.scala  0.59s user 0.09s system 53% cpu 1.271 total% rm *.class % time fsc A.scalafsc A.scala  0.59s user 0.09s system 51% cpu 1.320 total% time fsc -shutdown[Compile server exited]fsc -shutdown  0.61s user 0.09s system 132% cpu 0.524 total%

コンパイル時間の短縮...

Java VM をあげさげしていては負けだと思ったので、fsc のプロトコルを話すクライアントをRuby で書いてみた。

#! /usr/bin/ruby                                                                require 'socket'require 'pathname'def find_tmp_dir  Pathname.new(`which scala`.chomp).dirname + '../var/scala-devel'enddef find_port(dir)  ports = dir.entries.grep(/^\d+$/)  raise "Failed to find port file." if ports.empty?  return ports[0], (dir + ports[0]).read.chompenddef open_socket  port, password = find_port(find_tmp_dir + 'scalac-compile-server-port')  socket = TCPSocket.open('localhost', port)  socket.puts(password)  return socketenddef transform_argv(argv)  dir = if argv.include?('-d')          []        else          ['-d', '.']        end  (dir + argv).map do |i|    if i =~ /^-/      i    else      Pathname.new(i).realpath    end  endendargv = transform_argv(ARGV)socket = begin           open_socket         rescue           exit(system('fsc', *argv))         endsocket.puts(argv.join("\0"))print socket.read

だいぶ速い。

% time rfsc A.scala  rfsc A.scala  0.60s user 0.11s system 16% cpu 4.308 total% rm *.class       % time rfsc A.scalarfsc A.scala  0.01s user 0.01s system 1% cpu 1.198 total% time rfsc -shutdown[Compile server exited]rfsc -shutdown  0.01s user 0.01s system 65% cpu 0.025 total%

しかしなぜにこんなにも Java VM は起動が遅いんだろう。そこは Java の戦場じゃなかったというのはわかるけど、それにしても遅い。

0 comments
riddle for guest comment authorization:
Where is the capital city of Japan? ...

blog.8-p.info加藤和良 の個人的なブログで、プログラミングのはなしが多めです。


[8]ページ先頭

©2009-2025 Movatter.jp