ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:85623] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
@ 2018-02-19  1:10 ` sam.saffron
  2018-02-19  2:14 ` [ruby-core:85628] " merch-redmine
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: sam.saffron @ 2018-02-19  1:10 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been reported by sam.saffron (Sam Saffron).

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489

* Author: sam.saffron (Sam Saffron)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85628] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
  2018-02-19  1:10 ` [ruby-core:85623] [Ruby trunk Feature#14489] MJIT needs a reusable cache sam.saffron
@ 2018-02-19  2:14 ` merch-redmine
  2018-02-19  2:39   ` [ruby-core:85630] " Eric Wong
  2018-02-19 14:14 ` [ruby-core:85649] [Ruby trunk Feature#14489][Feedback] " takashikkbn
                   ` (9 subsequent siblings)
  11 siblings, 1 reply; 14+ messages in thread
From: merch-redmine @ 2018-02-19  2:14 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by jeremyevans0 (Jeremy Evans).


sam.saffron (Sam Saffron) wrote:
> It can use an ISEQ SHA1 hash as the key to the cache.

If this feature is added, it should at least use SHA256 as the hash function.  While the currently known SHA1 weaknesses may not matter in this particular case (if you are running untrusted code, you already have worse problems), it doesn't make sense to introduce usage of SHA1 in new code in cases where it is feasible to use a better hash function.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70416

* Author: sam.saffron (Sam Saffron)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85630] Re: [Ruby trunk Feature#14489] MJIT needs a reusable cache
  2018-02-19  2:14 ` [ruby-core:85628] " merch-redmine
@ 2018-02-19  2:39   ` Eric Wong
  0 siblings, 0 replies; 14+ messages in thread
From: Eric Wong @ 2018-02-19  2:39 UTC (permalink / raw
  To: ruby-core

merch-redmine@jeremyevans.net wrote:
> sam.saffron (Sam Saffron) wrote:
> > It can use an ISEQ SHA1 hash as the key to the cache.
> 
> If this feature is added, it should at least use SHA256 as the
> hash function.  While the currently known SHA1 weaknesses may
> not matter in this particular case (if you are running
> untrusted code, you already have worse problems), it doesn't
> make sense to introduce usage of SHA1 in new code in cases
> where it is feasible to use a better hash function.

Agreed; and it needs to be written with hash agility in mind
for the future when SHA256 becomes insufficient.

Also, I think https://github.com/ko1/yomikomu should be in
stdlib(*) and there will be code sharing opportunity for
JIT and ISeq caches.



(*) because rubygems itself is a startup bottleneck for me

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85649] [Ruby trunk Feature#14489][Feedback] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
  2018-02-19  1:10 ` [ruby-core:85623] [Ruby trunk Feature#14489] MJIT needs a reusable cache sam.saffron
  2018-02-19  2:14 ` [ruby-core:85628] " merch-redmine
@ 2018-02-19 14:14 ` takashikkbn
  2018-02-19 20:51 ` [ruby-core:85655] [Ruby trunk Feature#14489] " sam.saffron
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: takashikkbn @ 2018-02-19 14:14 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).

Status changed from Open to Feedback

By the way, one thing I want to share is that currently JIT-ed function is not reusable for another process. That's because it embeds class serial that can be changed in next boot for inlining things, and pointers of ISeq / call cache that can be changed too. This ticket requires giving up some optimizations and need indirection in generated code, and it may make JIT-ed code slow. 

I agree that it's good to decrease time to warm up, but if it requires JIT to be slow, it doesn't make sense to me.

> Also, I think https://github.com/ko1/yomikomu should be in
stdlib(*) and there will be code sharing opportunity for
JIT and ISeq caches.

How does yomikomu.gem improve the boot time? I've thought the default way of ISeq serialization costs and bootsnap improves the performance by another way. I know bootsnap doesn't work with trunk though.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70441

* Author: sam.saffron (Sam Saffron)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85655] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-02-19 14:14 ` [ruby-core:85649] [Ruby trunk Feature#14489][Feedback] " takashikkbn
@ 2018-02-19 20:51 ` sam.saffron
  2018-02-20  3:00 ` [ruby-core:85664] " takashikkbn
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: sam.saffron @ 2018-02-19 20:51 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by sam.saffron (Sam Saffron).


> By the way, one thing I want to share is that currently JIT-ed function is not reusable for another process. That's because it embeds class serial that can be changed in next boot for inlining things, and pointers of ISeq / call cache that can be changed too. This ticket requires giving up some optimizations and need indirection in generated code, and it may make JIT-ed code slow.

A big question though is if the binaries can have some sort of manifest that allows you to run a pre-processor and do a simple string replace? Completely agree you don't want to lose on any of the optimisations... but GCC is slow and running it 5000 times takes a very very long time. 


Another technique that may improve performance would be ISEQ bundling. So each .so file contains say up to 100 methods. Then you call GCC significantly less time, load less so files but pay a certain price for cache invalidation. 

> How does yomikomu.gem improve the boot time? I've thought the default way of ISeq serialization costs and bootsnap improves the performance by another way. I know bootsnap doesn't work with trunk though.

Yes we really want to fix bootsnap on current trunk, it is the goto gem people use. Performance wise in certain situations bootsnap can make **completely unusable setups**, usable. For example: https://meta.discourse.org/t/installation-notes-for-discourse-on-bash-for-windows/48141/13?u=sam

without bootsnap: boot time **31 seconds**
with bootsnap: boot time **4.5 seconds**


----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70446

* Author: sam.saffron (Sam Saffron)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85664] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-02-19 20:51 ` [ruby-core:85655] [Ruby trunk Feature#14489] " sam.saffron
@ 2018-02-20  3:00 ` takashikkbn
  2018-02-21  6:22 ` [ruby-core:85717] " hsbt
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: takashikkbn @ 2018-02-20  3:00 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).


Btw, I commented:

> I've thought the default way of ISeq serialization costs and bootsnap improves the performance by another way.

But ko1 pointed out they should be basically the same. So please never mind about that part of my comment.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70455

* Author: sam.saffron (Sam Saffron)
* Status: Feedback
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85717] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-02-20  3:00 ` [ruby-core:85664] " takashikkbn
@ 2018-02-21  6:22 ` hsbt
  2018-02-24  5:51 ` [ruby-core:85791] [Ruby trunk Feature#14489][Rejected] " takashikkbn
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: hsbt @ 2018-02-21  6:22 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by hsbt (Hiroshi SHIBATA).

Assignee set to k0kubun (Takashi Kokubun)

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70523

* Author: sam.saffron (Sam Saffron)
* Status: Feedback
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85791] [Ruby trunk Feature#14489][Rejected] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-02-21  6:22 ` [ruby-core:85717] " hsbt
@ 2018-02-24  5:51 ` takashikkbn
  2018-02-24 12:06 ` [ruby-core:85794] [Ruby trunk Feature#14489] " eregontp
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: takashikkbn @ 2018-02-24  5:51 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).

Status changed from Feedback to Rejected

> A big question though is if the binaries can have some sort of manifest that allows you to run a pre-processor and do a simple string replace?

This might resolve performance decrease in indirection. But the optimized code relies on the runtime value of call cache. So even if we cache it, we can't use such code until we call them. One option is loading it after first call, but it may have different cache for early calls.

> but GCC is slow and running it 5000 times takes a very very long time.

Do we really need to load JIT-ed 5000 methods from first? MJIT would compile methods which need to be JIT-ed first. So the boot time should not require 5000 times compilation. Also JIT is basically for long running program. Thus I don't think it's not a fatal problem. I think this is too early to introduce while JIT compiler is massively changed.

I still agree that the problem yomikomu/bootsnap solves is good to be addressed. But it's for Feature #14492.
Let me consider this again at least after Feature #14492 is introduced.  Please let me focus on other problems, especially on Bug #14490.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70643

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85794] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-02-24  5:51 ` [ruby-core:85791] [Ruby trunk Feature#14489][Rejected] " takashikkbn
@ 2018-02-24 12:06 ` eregontp
  2018-02-24 14:20 ` [ruby-core:85797] " takashikkbn
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: eregontp @ 2018-02-24 12:06 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by Eregon (Benoit Daloze).


One simple way that might help here is to make the default for --jit-min-calls much higher.
Compiling after only 5 calls by default seems very early.
Figuring out a better compilation threshold or heuristic would compile much less during RubyGems and Rails boot.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70646

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85797] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2018-02-24 12:06 ` [ruby-core:85794] [Ruby trunk Feature#14489] " eregontp
@ 2018-02-24 14:20 ` takashikkbn
  2018-03-07 13:02 ` [ruby-core:85967] " s.wanabe
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: takashikkbn @ 2018-02-24 14:20 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).


I agree with the direction. After resolving the slowness on Rails, we might be able to tune the default for discourse benchmark or something, to improve the boot time.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70648

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 








-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85967] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2018-02-24 14:20 ` [ruby-core:85797] " takashikkbn
@ 2018-03-07 13:02 ` s.wanabe
  2018-03-07 13:50 ` [ruby-core:85968] " takashikkbn
  2018-03-07 16:26 ` [ruby-core:85979] " takashikkbn
  11 siblings, 0 replies; 14+ messages in thread
From: s.wanabe @ 2018-03-07 13:02 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by wanabe (_ wanabe).

File 14489.patch added

.o file may be reusable if it can be separated from embedded value.
How about `extern const TYPE var;` place holders and other .c file that defines `const TYPE var = (val)`?
Here is a just PoC patch based on r62681 and a result example.

```
$ rm -r ~/.cache/ruby-mjit
$ time ruby --jit-wait --jit-cache-objs -e 'nil'

real	0m18.714s
user	0m17.718s
sys	0m1.828s
$ time ruby --jit-wait --jit-cache-objs -e 'nil'

real	0m1.656s
user	0m1.289s
sys	0m0.650s
$ time ruby --jit-wait -e 'nil'

real	0m16.731s
user	0m15.989s
sys	0m1.236s
$ find ~/.cache/ruby-mjit -name "*.o"|wc -l
87
```

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70833

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 






---Files--------------------------------
14489.patch (29.8 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85968] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2018-03-07 13:02 ` [ruby-core:85967] " s.wanabe
@ 2018-03-07 13:50 ` takashikkbn
  2018-03-07 15:11   ` [ruby-core:85972] " Vladimir Makarov
  2018-03-07 16:26 ` [ruby-core:85979] " takashikkbn
  11 siblings, 1 reply; 14+ messages in thread
From: takashikkbn @ 2018-03-07 13:50 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).


We should make sure what we're going to solve here first before introducing such mechanism. At least I prefer having Feature#14492 first and I suspect boot time would not be the issue after that. With --jit enabled, it takes time to wait for shutting down MJIT worker and it's sometimes considered as kind of boot time issue for short running scripts, but it's totally different issue from this ticket.

And I also suspect that the cached code might be inefficient because some aggressive optimization using cache like class_serial would be unavailable. Just translating instructions to native code wouldn't make big difference from VM execution, and we need inlining which depends on cache key that can't be known before execution. Then it may become even slower than original ISeq execution by increasing the number of VM invocations.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70834

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 






---Files--------------------------------
14489.patch (29.8 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85972] Re: [Ruby trunk Feature#14489] MJIT needs a reusable cache
  2018-03-07 13:50 ` [ruby-core:85968] " takashikkbn
@ 2018-03-07 15:11   ` Vladimir Makarov
  0 siblings, 0 replies; 14+ messages in thread
From: Vladimir Makarov @ 2018-03-07 15:11 UTC (permalink / raw
  To: Ruby developers, takashikkbn



On 03/07/2018 08:50 AM, takashikkbn@gmail.com wrote:
> Issue #14489 has been updated by k0kubun (Takashi Kokubun).
>
>
> We should make sure what we're going to solve here first before introducing such mechanism. At least I prefer having Feature#14492 first and I suspect boot time would not be the issue after that. With --jit enabled, it takes time to wait for shutting down MJIT worker and it's sometimes considered as kind of boot time issue for short running scripts, but it's totally different issue from this ticket.
I'd also prefer to solve shutting down MJIT first.  Right now, MJIT is 
just waiting for all processes finishing (e.g. compilation of the header 
file) even if it is already known that the result will be not used.  If 
we implement canceling the processes, the run time of small scripts 
would be a smaller problem.

This task was on my todo list.  I'll probably start working on it in May 
if nobody starts working on it before.
> And I also suspect that the cached code might be inefficient because some aggressive optimization using cache like class_serial would be unavailable. Just translating instructions to native code wouldn't make big difference from VM execution, and we need inlining which depends on cache key that can't be known before execution. Then it may become even slower than original ISeq execution by increasing the number of VM invocations.
>
Takashi, I am also agree with you here about the optimizations.

I also thought about caching from MJIT project start.  It still can be 
helpful in many cases but dealing with security vulnerabilities of 
caching should be considered seriously first.

I recently started some research work in my spare time on a lighter JIT 
whose compilation time might be at least 100 times faster but code is 
worse.  It is an ambitious project and probably will take a lot of time 
even I am going to reuse most of MJIT code but if it is implemented, it 
could be used as tier 1 JIT for practically any method and the current 
MJIT based on C compilers could be a tier 2 JIT used for more frequently 
executed methods to generate a better performance code.  A lighter JIT 
project will have a slow development pace as we need to do a lot for 
improving MJIT based on C compilers (inlining, some floating point code 
improvements i am considering).  I am planning to attend RubyKaigi 2018 
and if you visit it too we could discuss MJIT development and the 
lighter JIT project.


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [ruby-core:85979] [Ruby trunk Feature#14489] MJIT needs a reusable cache
       [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2018-03-07 13:50 ` [ruby-core:85968] " takashikkbn
@ 2018-03-07 16:26 ` takashikkbn
  11 siblings, 0 replies; 14+ messages in thread
From: takashikkbn @ 2018-03-07 16:26 UTC (permalink / raw
  To: ruby-core

Issue #14489 has been updated by k0kubun (Takashi Kokubun).


Yeah, having capability to shut down MJIT worker earlier looks important, especially when it becomes matured and we consider enabling it by default.

It's interesting to know your new project of multi-tier JIT. If inlining takes longer compilation time or consumes larger memory, it would make a lot of sense.

Also I'm very excited to know I'll have opportunity to have a talk with you again. I'll go to RubyKaigi 2018 for sure. Let's discuss about them.

----------------------------------------
Feature #14489: MJIT needs a reusable cache
https://bugs.ruby-lang.org/issues/14489#change-70846

* Author: sam.saffron (Sam Saffron)
* Status: Rejected
* Priority: Normal
* Assignee: k0kubun (Takashi Kokubun)
* Target version: 
----------------------------------------
Currently on Discourse boot I notice a few minutes of jitting every time you boot it:

This is a redacted output: https://gist.github.com/SamSaffron/4e18c2dacf476f1f27275f5b5d7bbb97 

CPU is spinning hard compiling temp file after temp file for **minutes**:

> JIT success (213.1ms): platform_string@/home/sam/.rbenv/versions/master/lib/ruby/gems/2.6.0/gems/bundler-1.16.1/lib/bundler/lazy_specification.rb:18 -> /tmp/_ruby_mjit_p6914u199.c

and so on.

Instead, mjit should have a reusable cache on disk it first tries fetching from prior to re-compiling. It can use an ISEQ SHA1 hash as the key to the cache. 






---Files--------------------------------
14489.patch (29.8 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-03-07 16:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-14489.20180219011031@ruby-lang.org>
2018-02-19  1:10 ` [ruby-core:85623] [Ruby trunk Feature#14489] MJIT needs a reusable cache sam.saffron
2018-02-19  2:14 ` [ruby-core:85628] " merch-redmine
2018-02-19  2:39   ` [ruby-core:85630] " Eric Wong
2018-02-19 14:14 ` [ruby-core:85649] [Ruby trunk Feature#14489][Feedback] " takashikkbn
2018-02-19 20:51 ` [ruby-core:85655] [Ruby trunk Feature#14489] " sam.saffron
2018-02-20  3:00 ` [ruby-core:85664] " takashikkbn
2018-02-21  6:22 ` [ruby-core:85717] " hsbt
2018-02-24  5:51 ` [ruby-core:85791] [Ruby trunk Feature#14489][Rejected] " takashikkbn
2018-02-24 12:06 ` [ruby-core:85794] [Ruby trunk Feature#14489] " eregontp
2018-02-24 14:20 ` [ruby-core:85797] " takashikkbn
2018-03-07 13:02 ` [ruby-core:85967] " s.wanabe
2018-03-07 13:50 ` [ruby-core:85968] " takashikkbn
2018-03-07 15:11   ` [ruby-core:85972] " Vladimir Makarov
2018-03-07 16:26 ` [ruby-core:85979] " takashikkbn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).