duangsuse::Echo
720 subscribers
4.31K photos
131 videos
583 files
6.54K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
(啊果然
Ruby, Crystal, Elixir
irb, icr, iex
一个 Erlang BEAM 平台上的语言
#Ruby https://www.ruby-lang.org/zh_cn/news/2018/02/24/ruby-2-6-0-preview1-released/
JIT

Ruby 2.6 引入了 JIT (Just-in-time) 编译器的初始实现。

JIT 编译器旨在提升任何 Ruby 程序的执行速度。不同于其他语言中常见的 JIT 编译器,Ruby 的 JIT 编译器进行 JIT 编译的过程非常独特。其将生成的 C 代码打印至磁盘并 spawn 常见的 C 编译器进行代码的生成工作。详见:Vladimir Makarov 的 MJIT 组织。

如何使用:在命令行或 $RUBYOPT 环境变量中指定 --jit 参数。指定 --jit-verbose=1 将允许打印 JIT 编译过程中的调试信息。详见 ruby --help 查看更多其他选项。

此 JIT 发布的主要目的是检查平台的兼容性,以及在 2.6 版本发布前找出安全风险。目前 JIT 编译器只当 Ruby 由 gcc 或 clang 编译后编译器仍可被运行时发现时可用,除此之外你暂时无法使用 JIT。

作为 2.6.0-preview1,我们在为 JIT 的基础设施作准备,所以实现了很少的优化。你可以通过此版本中的 micro benchmarks 测量出潜在的性能提升,但这并 不是 准备好接受最终性能测试的 Ruby JIT 编译器,特别是对于大型应用,例如 Rails 的测试。

我们正着手实现 JIT 编译器的内联方法,这将有助于大幅提升 Ruby 的性能。此外,我们计划增加支持的平台的数量,而下一个目标是支持 Visual Studio。

请保持对 Ruby 新时代性能的关注。
提升 Proc#call 的速度,因为我们无需再关心 $SAFE。[功能 #14318]
🐤 之前的MRI 想调用一个Proc居然还有安全分级...?

提升了当 block 是代码块参数时 block.call 的性能。[功能 #14330]
Ruby 2.5 提升了代码块传递的性能。[功能 #14045] 另外,Ruby 2.6 提升了传递代码块调用时的性能。通过 micro-benchmark 我们观察到了 2.6 倍性能提升。
Ruby 2.6 0.01469111400001566 比 Ruby 2.3 0.01693017300021893 的确快一些(
duangsuse::Echo
Photo
dse@susepc:~$ pry
[1] pry(main)> RUBY_VERSION
=> "2.6.0"
This media is not supported in your browser
VIEW IN TELEGRAM
和 GeekApk API 一样独特(
一般基于 LLVM 的引擎可以直接使用 LLVM 内建的 JIT 支持,
JVM 大概也有一个实验性基于 LLVM 的 JIT 编译器... 也不知道是不是 C2 就基于 LLVM
Chez Scheme 也支持 JIT, 不过据淫王说连汇编器都是自己的... 🌚
PLT Scheme 大概是基于 GNU Lightning https://www.gnu.org/software/lightning/manual/lightning.html 的 (虽然我都不懂....
http://users.racket-lang.narkive.com/CeO6zgKL/plt-scheme-nanojit-an-alternative-to-llvm 9 years ago

MJIT 目前好像支持 clang 和 GCC C 两款 C 编译器,,,,, 也不知道是不是大都内联汇编
看到 MJIT 有这么清奇的设计 GeekApk API 如果不能上 OAuth 我就放心了(
膜拜语言实现 dalao, 我对底层一无所知(
(不仅如此连 Java 类型系统都不了解
(更别说 C# 那些更高级的语言特性和 CLR 非托管代码这些...
(连 Ruby 这么简单的东西都未曾完全了解
(Duck typing 比 C#和 Java 那一套是简单多了....
因为 这么菜
所以才只能做 GeekApk 这么低级的工作(
所以这个人辣还是要提高自己的姿势水平
This media is not supported in your browser
VIEW IN TELEGRAM
4.1 A function which increments a number by one

Let’s see how to create and use the sample incr function created in GNU lightning’s instruction set:

#include <stdio.h>
#include <lightning.h>

static jit_state_t *_jit;

typedef int (*pifi)(int); /* Pointer to Int Function of Int */

int main(int argc, char *argv[])
{
jit_node_t *in;
pifi incr;

init_jit(argv[0]);
_jit = jit_new_state();

jit_prolog(); /* prolog */
in = jit_arg(); /* in = arg */
jit_getarg(JIT_R0, in); /* getarg R0 */
jit_addi(JIT_R0, JIT_R0, 1); /* addi R0, R0, 1 */
jit_retr(JIT_R0); /* retr R0 */

incr = jit_emit();
jit_clear_state();

/* call the generated code, passing 5 as an argument */
printf("%d + 1 = %d\n", 5, incr(5));

jit_destroy_state();
finish_jit();
return 0;
}

Let’s examine the code line by line (well, almost…):

#include <lightning.h>

You already know about this. It defines all of GNU lightning’s macros.
static jit_state_t *_jit;

You might wonder about what is jit_state_t. It is a structure that stores jit code generation information. The name _jit is special, because since multiple jit generators can run at the same time, you must either #define _jit my_jit_state or name it _jit.
typedef int (*pifi)(int);

Just a handy typedef for a pointer to a function that takes an int and returns another.
jit_node_t *in;

Declares a variable to hold an identifier for a function argument. It is an opaque pointer, that will hold the return of a call to arg and be used as argument to getarg.
pifi incr;

Declares a function pointer variable to a function that receives an int and returns an int.
init_jit(argv[0]);

You must call this function before creating a jit_state_t object. This function does global state initialization, and may need to detect CPU or Operating System features. It receives a string argument that is later used to read symbols from a shared object using GNU binutils if disassembly was enabled at configure time. If no disassembly will be performed a NULL pointer can be used as argument.
_jit = jit_new_state();

This call initializes a GNU lightning jit state.
jit_prolog();

Ok, so we start generating code for our beloved function…
in = jit_arg();
jit_getarg(JIT_R0, in);

We retrieve the first (and only) argument, an integer, and store it into the general-purpose register R0.
jit_addi(JIT_R0, JIT_R0, 1);

We add one to the content of the register.
jit_retr(JIT_R0);

This instruction generates a standard function epilog that returns the contents of the R0 register.
incr = jit_emit();

This instruction is very important. It actually translates the GNU lightning macros used before to machine code, flushes the generated code area out of the processor’s instruction cache and return a pointer to the start of the code.
jit_clear_state();

This call cleanups any data not required for jit execution. Note that it must be called after any call to jit_print or jit_address, as this call destroy the GNU lightning intermediate representation.
printf("%d + 1 = %d", 5, incr(5));

Calling our function is this simple—it is not distinguishable from a normal C function call, the only difference being that incr is a variable.
jit_destroy_state();

Releases all memory associated with the jit context. It should be called after known the jit will no longer be called.
finish_jit();

This call cleanups any global state hold by GNU lightning, and is advisable to call it once jit code will no longer be generated.

GNU lightning abstracts two phases of dynamic code generation: selecting instructions that map the standard representation, and emitting binary code for these instructions. The client program has the responsibility of describing the code to be generated using the standard GNU lightning instruction set.


GNU Lightning JIT 库选了一个片段快速了解(
x86_64

sub $0x30,%rsp
mov %rbp,(%rsp)
mov %rsp,%rbp
sub $0x18,%rsp
mov %rdi,%rax mov %rdi, %rax
add $0x1,%rax inc %rax
mov %rbp,%rsp
mov (%rsp),%rbp
add $0x30,%rsp
retq retq
GNU Dalao