プリンキピア

第7章高水準プログラミング言語

INDUSTRY SPOTLIGHT産業の現場から
Using Proven HLLs実績のある高水準言語を使う
While runtime program management using virtual machines provides large flexibility gains, many industries that rely on large enterprise-level software to support demanding mission-critical business applications typically rely on more traditional runtime environments and older, proven HLLs. This is particularly true in the financial industry today. A good example is the use of Python as a core language (https://openstax.org/r/76PythonCorLang) for J.P. Morgan’s Athena program and Bank of America’s Quartz program. Why do you think this is the case?
英語のヒント
仮想マシンによる実行時のプログラム管理は、柔軟性を大幅に高める。しかし、要求の厳しい、業務に欠かせないアプリケーションを、大規模な企業向けソフトウェアで支えている多くの産業では、一般に、より伝統的な実行環境と、古くからある実績の確かな高水準言語を頼りにしている。現在の金融業界では、特にそうである。よい例が、J.P. MorganのAthenaプログラムとBank of AmericaのQuartzプログラムにおける、「中核言語としてのPythonの利用」(https://openstax.org/r/76PythonCorLang)である。なぜ、こうなっていると思うか。
Symbolic Debugging記号デバッグ
While debuggers are present in most virtual machines and integrated program development environments (IDEs) and provided by programming language interpreters, they also come as standalone tools. Symbolic debuggers understand high-level syntax. In short, a debugger finds errors in programs. It can also set parameters for stopping an execution should it reach a certain point in the source code or if a constant is read.
英語のヒント
デバッガーは、多くの仮想マシンや統合プログラム開発環境(IDE)に備わり、プログラミング言語のインタープリターからも提供されるが、単独のツールとしても存在する。記号デバッガーは、高水準の構文を理解する。端的にいうと、デバッガーはプログラム内の誤りを見つける。また、ソースコードのある地点に達した場合や、定数が読み取られた場合に、実行を止めるための条件を設定することもできる。

Code Optimization and Improvementコードの最適化と改善

The goal of code optimization is to rework parts of your code for efficiency. Some of the problem areas of optimization are redundant computations, as well as inefficient use of the hardware registers, multiple functional units (input, output), memory, and cache.
英語のヒント
コード最適化の目標は、効率を高めるために、コードの一部を作り直すことである。最適化の対象となる問題には、冗長な計算のほか、ハードウェアのレジスター、複数の機能単位(入力・出力)、メモリ、キャッシュの非効率な利用がある。
We can interpret the results of optimization to mean fast and/or decreasing memory requirements. Optimization is best carried out at multiple levels, one of which is at the basic block level. A basic block is a minimal length sequence of instructions that will always execute in its entirety if it executes at all, equivalent to a code block. Code improvement at the level of basic blocks is known as local optimization, consisting of eliminating redundant operations (unnecessary loads, common subexpression calculations), providing effective instruction scheduling, and providing register allocation.
英語のヒント
最適化の結果は、速度が上がることや、必要なメモリが減ることと捉えられる。最適化は複数の水準で行うのがよく、その一つが基本ブロックの水準である。基本ブロックは、実行されるなら必ず全体が実行される、最小限の長さの命令列であり、コードブロックに相当する。基本ブロックの水準で行うコード改善を、局所最適化という。冗長な演算(不要なロードや共通部分式の計算)を除くこと、効果的な命令スケジューリングを行うこと、レジスターを割り当てることからなる。
At higher levels, compilers review and analyze all subroutines for further improvements. The code improvements at multiple layers that include loop performance improvement, register allocation, and instruction scheduling is called global optimization.
英語のヒント
より高い水準では、コンパイラーがすべてのサブルーチンを調べて解析し、さらに改善する。ループ性能の改善、レジスター割り当て、命令スケジューリングを含む、複数の層にわたるコード改善を、大域最適化という。
THINK IT THROUGH考えてみよう
Understanding Optimization最適化を理解する
The medical industry views code optimization as a must-have. Most medical operations make use of patient portals for communication between patients and the medical practice. This requires both speed and platform portability such as Windows and Android. Because of this, Java is the language of choice (https://openstax.org/r/76LangofChoice) for these applications. Why is it important for programmers to understand code optimization techniques? Should they only rely on the optimizing compiler provided for the HLL they use? Why or why not? Will you become a better programmer by understanding the way that lower-level code works in order to have a high-level view of optimization?
英語のヒント
医療業界では、コード最適化を欠かせないものと考えている。多くの医療機関は、患者と医療提供者のコミュニケーションに、患者用ポータルを利用する。そのためには、速度と、WindowsやAndroidなどのプラットフォーム間での移植性が、どちらも必要になる。このため、これらのアプリケーションでは、Javaが「選ばれる言語」(https://openstax.org/r/76LangofChoice)となっている。プログラマーがコード最適化の技法を理解することは、なぜ重要なのか。使っている高水準言語の最適化コンパイラーだけに頼るべきだろうか。その理由、またはそうすべきでない理由は何か。低水準のコードの動作を理解して、最適化を高い視点から見渡せるようになれば、より優れたプログラマーになれるだろうか。
As with code optimization, code improvement also aims to increase execution speed. Code improvement focuses on eliminating basic blocks redundancy, loop improvements, and instruction scheduling. The biggest area of improvement focuses on the review and enhancement of the behavior of loops. Reordering loops can be difficult but rewarding as all data dependencies must be respected (loop-carried dependencies).
英語のヒント
コード最適化と同様に、コード改善も、実行速度の向上を目指す。コード改善では、基本ブロックの冗長性の排除、ループの改善、命令スケジューリングに重点を置く。最も大きな改善対象は、ループの振る舞いを見直し、高めることである。ループの順序変更は、すべてのデータ依存関係(ループをまたぐ依存関係)を守らなければならないため難しいことがあるが、取り組む価値はある。
The conclusion that one can form based on code optimization and code improvement is that the “need for speed” is paramount in today’s global software and internet environments.
英語のヒント
コード最適化とコード改善から導ける結論は、今日の世界規模のソフトウェアとインターネットの環境では、「速度への要求」が最優先されるということである。
CONCEPTS IN PRACTICE概念を実践する
Optimizing Your Code自分のコードを最適化する
Did you know that compilers can often improve the performance of your code? This process is called optimization. Optimizers can make your code run faster by using techniques such as removing unnecessary calculations, improving memory usage, and reorganizing code for better efficiency.
英語のヒント
コンパイラーがコードの性能を改善できることが多いと、知っていただろうか。この処理を最適化という。最適化器は、不要な計算の削除、メモリ使用の改善、効率を高めるためのコードの再編成などの技法を使って、コードを速く動かせる。
By understanding optimization techniques, you can write smoother code and use fewer resources. As a side note, mainstream programming language compilers provided by Microsoft and Oracle are designed to optimize the execution of programs. Microsoft’s .Net framework uses virtual machines that manage the CLR of various programming languages. The intermediate byte code generated by compilers that target these virtual machines is optimized using some of the techniques described in this chapter.
英語のヒント
最適化の技法を理解すると、より円滑に動くコードを書き、使用する資源を減らせる。なお、MicrosoftやOracleが提供する主流のプログラミング言語のコンパイラーは、プログラムの実行を最適化するように設計されている。Microsoftの.Netフレームワークは、さまざまなプログラミング言語のCLRを管理する仮想マシンを使う。これらの仮想マシンを対象とするコンパイラーが生成した中間バイトコードは、この章で説明した技法の一部を使って最適化される。