Skip to content

Commit f319111

Browse files
committed
[GR-44565] Use the system libyaml for psych as it is faster for warmup
PullRequest: truffleruby/3673
2 parents ae92a05 + d50ca32 commit f319111

25 files changed

+134
-13044
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Performance:
9999
* Marking of native structures wrapped in objects is now done on C call exit to reduce memory overhead (@aardvark179).
100100
* Splitting (copying) of call targets has been optimized by implementing `cloneUninitialized()` (@andrykonchin, @eregon).
101101
* `Process.pid` is now cached per process like `$$` (#2882, @horakivo)
102+
* Use the system `libyaml` for `psych` to improve warmup when parsing YAML (#2089, @eregon).
102103

103104
Changes:
104105

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ environment, for example, by unmounting system filesystems such as `/dev/shm`.
103103

104104
* [make and gcc](doc/user/installing-llvm.md) for building C and C++ extensions
105105
* [libssl](doc/user/installing-libssl.md) for the `openssl` C extension
106+
* [libyaml](doc/user/installing-libyaml.md) for the `psych` C extension
106107
* [zlib](doc/user/installing-zlib.md) for the `zlib` C extension
107108

108109
Without these dependencies, many libraries including RubyGems will not work.

ci.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,14 @@ local part_definitions = {
228228
packages+: {
229229
binutils: ">=2.30",
230230
ruby: "==" + mri_version,
231+
libyaml: "==0.2.5",
231232
},
232233
},
233234

234235
local linux_aarch64_deps = common.deps.sulong + {
235236
packages+: {
236237
ruby: "==3.0.2",
238+
libyaml: "==0.2.5",
237239
},
238240
},
239241

doc/user/installing-libssl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ To compile TruffleRuby against a non-system `libssl`, set `OPENSSL_PREFIX` while
1717
export OPENSSL_PREFIX=/path/to/my/openssl-1.1.0
1818
```
1919

20-
### RedHat-based: Fedora, Oracle Linux, etc
20+
### Fedora-based: RHEL, Oracle Linux, etc
2121

2222
```bash
2323
sudo dnf install openssl-devel

doc/user/installing-libyaml.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
layout: docs-experimental
3+
toc_group: ruby
4+
link_title: Installing LibYAML
5+
permalink: /reference-manual/ruby/InstallingLibYAML/
6+
---
7+
# Installing LibYAML
8+
9+
TruffleRuby requires to have `libyaml` installed, much like CRuby 3.2+ and Psych 5+.
10+
11+
If you experience `psych`-related errors saying it cannot find `libyaml`, it might help to recompile the `psych` gem by running `lib/truffle/post_install_hook.sh`.
12+
This is done automatically by Ruby managers, and mentioned in the post-install message when installing TruffleRuby via `gu install` in GraalVM.
13+
14+
### Fedora-based: RHEL, Oracle Linux, etc
15+
16+
```bash
17+
sudo dnf install libyaml-devel
18+
```
19+
20+
### Debian-based: Ubuntu, etc
21+
22+
```bash
23+
sudo apt-get install libyaml-dev
24+
```
25+
26+
### macOS
27+
28+
#### Homebrew
29+
30+
We recommend installing libssl via [Homebrew](https://brew.sh).
31+
32+
```bash
33+
brew install libyaml
34+
```
35+
36+
#### MacPorts
37+
38+
MacPorts should also work but is not actively tested.
39+
40+
```bash
41+
sudo port install libyaml
42+
```

doc/user/installing-llvm.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ If you are using an older version, see [the documentation for that version](http
1212

1313
The `make` utility as well as the dependencies of the toolchain still need to be available to build C and C++ extensions.
1414

15-
## RedHat-based: Fedora, Oracle Linux, etc.
15+
### Fedora-based: RHEL, Oracle Linux, etc
1616

1717
```bash
1818
sudo dnf install make gcc
1919
```
2020

21-
## Debian-based: Ubuntu, etc.
21+
### Debian-based: Ubuntu, etc
2222

2323
```bash
2424
sudo apt-get install make gcc
2525
```
2626

27-
## Mandriva-based and other Linux distributions
27+
### Mandriva-based and other Linux distributions
2828

2929
Note: Such distributions are not tested and not [supported](../../README.md#system-compatibility).
3030

@@ -40,7 +40,7 @@ cd /usr/lib/gcc
4040
sudo ln -s x86_64-mandriva-linux-gnu x86_64-linux-gnu
4141
```
4242

43-
## macOS
43+
### macOS
4444

4545
On macOS, make sure you have installed the command line developer tools from Xcode:
4646

doc/user/installing-zlib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ permalink: /reference-manual/ruby/Installingzlib/
88

99
TruffleRuby provides the `zlib` module but not the native `zlib` system library that the module uses.
1010

11-
### RedHat-based: Fedora, Oracle Linux, etc
11+
### Fedora-based: RHEL, Oracle Linux, etc
1212

1313
```bash
1414
sudo dnf install zlib-devel

doc/user/utf8-locale.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ locale
1818
shows no `="C"` and no warning.
1919
Instead, all values should be `"en_US.UTF-8"` or other regions but still `.UTF-8`.
2020

21-
### RedHat-based: Fedora, Oracle Linux, etc
21+
### Fedora-based: RHEL, Oracle Linux, etc
2222

2323
```bash
2424
export LANG=en_US.UTF-8

lib/truffle/post_install_hook.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
# Hook run after extraction in the installation directory by a Ruby installer.
33
# Useful to perform tasks that depend on the user machine and
4-
# cannot be generally done in advance before building the release tarball.
4+
# cannot be generally done in advance on another machine.
55

66
set -e
77

@@ -15,24 +15,38 @@ export TRUFFLERUBYOPT="--disable-gems $TRUFFLERUBYOPT"
1515

1616
cd "$root"
1717

18-
function recompile_openssl() {
19-
cd src/main/c/openssl
18+
function recompile() {
19+
ext="$1"
20+
cd "src/main/c/$ext"
2021
truffleruby -w extconf.rb
2122
if [ -z "$CORES" ]; then
2223
CORES=$(getconf _NPROCESSORS_ONLN || echo 1)
2324
fi
2425
make "--jobs=$CORES"
25-
cp "openssl.$(truffleruby -rrbconfig -e "print RbConfig::CONFIG['DLEXT']")" "$root/lib/mri"
26+
cp "$ext.$(truffleruby -rrbconfig -e "print RbConfig::CONFIG['DLEXT']")" "$root/lib/mri"
27+
cd "$root"
28+
echo
2629
}
2730

2831
if [ "$TRUFFLERUBY_RECOMPILE_OPENSSL" == "false" ]; then
29-
echo "Skipping recompilation of the OpenSSL extension (TRUFFLERUBY_RECOMPILE_OPENSSL=false)"
32+
echo "Skipping recompilation of the OpenSSL C extension (TRUFFLERUBY_RECOMPILE_OPENSSL=false)"
3033
elif [ "$TRUFFLERUBY_RECOMPILE_OPENSSL" == "true" ]; then
3134
echo "Recompiling the OpenSSL C extension (TRUFFLERUBY_RECOMPILE_OPENSSL=true)"
32-
recompile_openssl
35+
recompile openssl
3336
else
3437
echo "Recompiling the OpenSSL C extension (against the installed libssl)"
35-
recompile_openssl
38+
recompile openssl
39+
fi
40+
41+
# Recompiling psych is needed on macOS if a non-default Homebrew prefix or not using Homebrew (e.g. MacPorts)
42+
if [ "$TRUFFLERUBY_RECOMPILE_PSYCH" == "false" ]; then
43+
echo "Skipping recompilation of the Psych C extension (TRUFFLERUBY_RECOMPILE_PSYCH=false)"
44+
elif [ "$TRUFFLERUBY_RECOMPILE_PSYCH" == "true" ]; then
45+
echo "Recompiling the Psych C extension (TRUFFLERUBY_RECOMPILE_PSYCH=true)"
46+
recompile psych
47+
else
48+
echo "Recompiling the Psych C extension (against the installed libyaml)"
49+
recompile psych
3650
fi
3751

3852
echo "TruffleRuby was successfully installed in $root"

lib/truffle/truffle/libyaml-prefix.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
2+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
3+
# redistribute it and/or modify it under the terms of the:
4+
#
5+
# Eclipse Public License version 2.0, or
6+
# GNU General Public License version 2, or
7+
# GNU Lesser General Public License version 2.1.
8+
9+
# Set LIBYAML_PREFIX in ENV to find the libyaml headers
10+
11+
search_homebrew = -> homebrew {
12+
if prefix = "#{homebrew}/opt/libyaml" and Dir.exist?(prefix)
13+
prefix
14+
end
15+
}
16+
17+
if Truffle::Platform.darwin? && !ENV['LIBYAML_PREFIX']
18+
default_homebrew_prefix = Truffle::System.host_cpu == 'aarch64' ? '/opt/homebrew' : '/usr/local'
19+
if prefix = search_homebrew.call(default_homebrew_prefix)
20+
# found
21+
else
22+
homebrew = `brew --prefix 2>/dev/null`.strip
23+
homebrew = nil unless $?.success? and !homebrew.empty? and Dir.exist?(homebrew)
24+
25+
if homebrew and prefix = search_homebrew.call(homebrew)
26+
# found
27+
elsif Dir.exist?('/opt/local/include/libyaml') # MacPorts
28+
prefix = '/opt/local'
29+
end
30+
end
31+
32+
if prefix
33+
ENV['LIBYAML_PREFIX'] = prefix
34+
else
35+
abort 'Could not find libyaml headers, install via Homebrew or MacPorts or set LIBYAML_PREFIX'
36+
end
37+
end
38+
39+
if libyaml_prefix = ENV['LIBYAML_PREFIX']
40+
Truffle::Debug.log_config("Found libyaml in #{libyaml_prefix}")
41+
end

0 commit comments

Comments
 (0)