Skip to content

Commit

Permalink
add lightning talk for rubyconf X
Browse files Browse the repository at this point in the history
  • Loading branch information
timfel committed Nov 12, 2010
1 parent dd44b83 commit 09978cb
Show file tree
Hide file tree
Showing 27 changed files with 378 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 11_2010_rubyconf_jruby-cext/C-API/01_mri.md
@@ -0,0 +1,20 @@
!SLIDE
## Internal API in MRI

@@@ c
/* call-seq:
* ary.each {|item| block } -> ary
* ary.each -> an_enumerator
*/
VALUE
rb_ary_each(VALUE ary)
{
long i;
RETURN_ENUMERATOR(ary, 0, 0);
for (i=0; i<RARRAY_LEN(ary); i++) {
rb_yield(RARRAY_PTR(ary)[i]);
}
return ary;
}

15 changes: 15 additions & 0 deletions 11_2010_rubyconf_jruby-cext/C-API/02_jruby.md
@@ -0,0 +1,15 @@
!SLIDE
## Internal API in JRuby

@@@ java
/** rb_ary_each */
public IRubyObject eachCommon(ThreadContext context, Block block) {
if (!block.isGiven()) {
throw context.getRuntime().newLocalJumpErrorNoBlock();
}
for (int i = 0; i < realLength; i++) {
block.yield(context, values[begin + i]);
}
return this;
}

124 changes: 124 additions & 0 deletions 11_2010_rubyconf_jruby-cext/C-API/03_cexts.md
@@ -0,0 +1,124 @@
!SLIDE
# There's different parts to the C API

!SLIDE
# Ruby code in C

@@@ c
/*
* call-seq:
* ary << obj -> ary
*
* Append---Pushes the given object on to the end of this array. This
* expression returns the array itself, so several appends
* may be chained together.
*
* [ 1, 2 ] << "c" << "d" << [ 3, 4 ]
* #=> [ 1, 2, "c", "d", [ 3, 4 ] ]
*
*/
VALUE rb_ary_push(VALUE ary, VALUE item)

!SLIDE
# This is easy to do…

@@@ c
extern "C" VALUE
rb_ary_push(VALUE array, VALUE val)
{
return callMethod(array, "push", 1, val);
}

---
@@@ java
public class JRuby {
public static long callRubyMethod(IRubyObject recv, Object methodName, IRubyObject[] args) {
IRubyObject retval = recv.callMethod(recv.getRuntime().getCurrentContext(),
methodName.toString(), args);

return Handle.nativeHandle(retval);
}

## Not fast, but safe.

!SLIDE
# On to more scary stuff

@@@ ruby
>> str = "42"; c_mutate_string(str); puts str
==> 23

---

@@@ c
VALUE c_mutate_string(VALUE ruby_string) {
char* c_string = RSTRING(ruby_string)->ptr;
}
c_string[0] = '2';
c_string[1] = '3';

!SLIDE
# Synchronization of Structures in JRuby
@@@ c
struct RString {
struct RBasic basic;
long len;
char *ptr;
long capa;
};
#define RSTRING(str) jruby_rstring((str))

!SLIDE

@@@ c
extern "C" struct RString*
jruby_rstring(VALUE v)
{
return jruby_str(v)->toRString(false);
}

!SLIDE smaller
@@@ c
RString* RubyString::toRString(bool readonly)
{
JLocalEnv env;
rwdata.jsync.data = this;
rwdata.jsync.sync = RubyString_jsync;
rwdata.nsync.data = this;
rwdata.nsync.sync = RubyString_nsync;
rwdata.clean.data = this;
rwdata.clean.sync = RubyString_clean;
rwdata.rstring = (RString *) j2p(env->CallStaticLongMethod(JRuby_class, JRuby_getRString, obj));
checkExceptions(env);
rwdata.readonly = readonly;

TAILQ_INSERT_TAIL(&jruby::cleanq, &rwdata.clean, syncq);
TAILQ_INSERT_TAIL(&jruby::jsyncq, &rwdata.jsync, syncq);
if (!readonly)
TAILQ_INSERT_TAIL(&jruby::nsyncq, &rwdata.nsync, syncq);
nsync(env);

return rwdata.rstring;
}

!SLIDE center
### If we need more, the situation is dire indeed.
![dire](dire.png)

!SLIDE smbullets
# Things like
* `rb_iterate`
* `NODE(x)`
* `rb_thread_blocking_region`
* `rb_io_fd`
*

<div style="font-size: 2em">
Either don't work or work unsafely.
</div><br/>
<div style="font-size: 1.2em">
Try those methods on JRuby and they might eat your JVM, wipe your hard-drive,
hunt down your children and drink their blood.
<div>
11 changes: 11 additions & 0 deletions 11_2010_rubyconf_jruby-cext/C-API/04_yay.md
@@ -0,0 +1,11 @@
!SLIDE commandline smaller
# Some things work, though
### (yay!)

$:☯ gem install thin
WARNING: JRuby does not support native extensions or the `mkmf'
library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
Building native extensions. This could take a while...
Successfully installed thin-1.2.7
Binary file added 11_2010_rubyconf_jruby-cext/C-API/dire.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions 11_2010_rubyconf_jruby-cext/cext_support/01.md
@@ -0,0 +1,34 @@
!SLIDE commandline
### “Have you tried css_sprite?”

@@@ bash
$:☯ script/plugin install git://github.com/flyerhzm/css_sprite.git
$:☯ rake css_sprite:start
jruby/.../custom_require.rb:31:in `require': no such file to load
-- RMagick (LoadError)

!SLIDE commandline
### “Using the new, hot, evented web server?” ###

@@@ bash
$:☯ gem install thin
WARNING: JRuby does not support native extensions or the `mkmf' library.
Check http://kenai.com/projects/jruby for alternatives.

!SLIDE bullets
### Are you using ###
* MongoDB
* Markdown
* HTML processing?

!SLIDE bullets
### Then you might want to speed up with ###
* _bson_ext_ <span class="side-note">MongoDB driver</span>
* _rdiscount_ <span class="side-note">Markdown processor</span>
* _escape_utils_ <span class="side-note">HTML escaping for Webapps</span>

!SLIDE smbullets
### The current approach is to rewrite extensions in Java – that's
* expensive,
* inefficient,
* and bloody boring!
22 changes: 22 additions & 0 deletions 11_2010_rubyconf_jruby-cext/cext_support/02_real_support.md
@@ -0,0 +1,22 @@
!SLIDE commandline incremental
# C ext support – yay!

$:☯ gem install thin
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
Building native extensions. This could take a while...
Successfully installed thin-1.2.7

!SLIDE commandline
# C ext support – yay!

$:☯ gem install thin
WARNING: JRuby does not support native extensions or the `mkmf' library very well.
Check http://kenai.com/projects/jruby/pages/Home for alternatives.
Building native extensions. This could take a while...
Successfully installed thin-1.2.7

# Thanks for listening
Check it out at [github.com/jruby/tree/cext](http://github.com/jruby/jruby/tree/cext)
6 changes: 6 additions & 0 deletions 11_2010_rubyconf_jruby-cext/gaining_speed/00.md
@@ -0,0 +1,6 @@
!SLIDE smbullets numberbullets
# Speeding up?
* Rethink Algorithms
* Change Execution Environment
* Offload via FFI
* Rewrite in C
4 changes: 4 additions & 0 deletions 11_2010_rubyconf_jruby-cext/gaining_speed/01_algorithms.md
@@ -0,0 +1,4 @@
!SLIDE center
# Rethink Algorithms
### We have heard about this from others ...
![tenderlove](tenderlove.png)
3 changes: 3 additions & 0 deletions 11_2010_rubyconf_jruby-cext/gaining_speed/02_vm.md
@@ -0,0 +1,3 @@
!SLIDE center
# Just run on faster machines
![super computer](bluegene.png)
9 changes: 9 additions & 0 deletions 11_2010_rubyconf_jruby-cext/gaining_speed/03_ffi.md
@@ -0,0 +1,9 @@
!SLIDE smbullets
# “But there's a fast C library already out there!”

!SLIDE center
# FFI To The Rescue!
![to-the-rescue](to-the-rescue.png)

!SLIDE
# But FFI is only applicable to a limited number of problems
4 changes: 4 additions & 0 deletions 11_2010_rubyconf_jruby-cext/gaining_speed/04_c_extensions.md
@@ -0,0 +1,4 @@
!SLIDE center
# Into the Magic Country
## (With Ruby C Extensions)
![promised-land](promised-land.png)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions 11_2010_rubyconf_jruby-cext/opening/01_slide.md
@@ -0,0 +1,19 @@
!SLIDE smbullets smsmbullets
# C Extension Support For JRuby

* Tim Felgentreff
* Finn GmbH
* [blog.bithug.org](http://blog.bithug.org/), [github/timfel](http://github.com/timfel), [@timfelgentreff](http://twitter.com/timfelgentreff)<br/><br/><br/><br/>

!SLIDE center
# Ruby is about abstracting away
![clouds](clouds.png)

!SLIDE center
# Ruby is slow
#### (when benchmarking classic CS problems)
![language_bench](language_bench.png)

!SLIDE center
# Ruby _can_ do heavy lifting
![heavy-lifting](heavy-lifting.png)
Binary file added 11_2010_rubyconf_jruby-cext/opening/clouds.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,11 @@
!SLIDE smbullets

## So why should I pick JRuby? ##

* Runs on many JVMs
1. Android, WebOS, Symbian, NXT
3. Hosting solutions without Ruby
* Runs Ruby as Java
1. Integrate with Java Frameworks (SWT, Spring)
2. Use enterprise-level Java libraries (JDBC)
* JIT compiler and Hotspot for massive speed boosts
89 changes: 89 additions & 0 deletions 11_2010_rubyconf_jruby-cext/rug-b.css
@@ -0,0 +1,89 @@
code {
font-size: 22px;
}

h2 {
top: -10%;
}

table {
align-left: auto;
align-right: auto;
font-size: 32px;
border-spacing: 6px;
}

thead {
border-bottom: 1px solid #555;
}

td {
padding: 12px;
}

.sidebar {
left: 0px;
width: 15%;
position: relative;
}

ol {
list-style: lower-roman;
}

.smbullets ul li {
text-align: left;
margin-left: 15%;
}

.bullets ul li {
padding: 25px 25px 25px 25%;
padding-left: 25%;
text-align: left;
}

.smsmbullets ul li {
text-align: center;
font-size: 18px;
margin-top: -12px;
margin-left: 0%;
}

.numberbullets ul li {
list-style: decimal;
}

.side-note {
color: #555;
font-size: 50%;
}

.right_and_up {
float: right;
margin-top: -10%;
}

img {
max-width: 1020px;
max-height: 720px;
}

.rubinius_logo img {
height: 78px;
position: absolute;
width: 50px;
margin-left: 45px;
}

.jruby_logo img {
height: 45px;
position: absolute;
width: 156px;
}

.ruby_logo img {
height: 48px;
position: absolute;
width: 48px;
margin-left: 55px;
}
7 changes: 7 additions & 0 deletions 11_2010_rubyconf_jruby-cext/showoff.json
@@ -0,0 +1,7 @@
{ "name": "JRuby C API support",
"sections": [
{"section": "opening"},
{"section": "gaining_speed"},
{"section": "C-API"}
]
}

0 comments on commit 09978cb

Please sign in to comment.