Skip to content

Commit f0edf95

Browse files
committed
Load all UnicodeCodeRange eagerly on Native Image
* Which removes the need to keep tables/*.bin resources. Most tables were actually not needed at runtime since most tables are already loaded at image build time. * Image size is slighter smaller: 151MB instead of 156MB on Linux. * Startup and memory footprint seem unaffected.
1 parent ad9b5da commit f0edf95

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/main/java/META-INF/native-image/resource-config.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/org/truffleruby/core/encoding/TranscodingManager.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,26 @@
3232
*/
3333
package org.truffleruby.core.encoding;
3434

35-
import java.util.ArrayList;
3635
import java.util.HashMap;
3736
import java.util.HashSet;
38-
import java.util.List;
3937
import java.util.Map;
4038
import java.util.Set;
4139

42-
import org.jcodings.transcode.Transcoder;
4340
import org.jcodings.transcode.TranscoderDB;
41+
import org.jcodings.unicode.UnicodeCodeRange;
42+
import org.jcodings.unicode.UnicodeEncoding;
4443
import org.jcodings.util.CaseInsensitiveBytesHash;
4544
import org.jcodings.util.Hash;
4645

4746
import com.oracle.truffle.api.TruffleOptions;
4847
import org.truffleruby.core.rope.RopeOperations;
4948
import org.truffleruby.core.string.StringUtils;
5049

50+
/** This class computes all direct transcoder paths for both JVM and Native Image as a convenient-to-access Map. On
51+
* Native Image, it also loads eagerly everything that would need the tables/*.bin resources, so they are not needed at
52+
* runtime */
5153
public class TranscodingManager {
5254

53-
private static final List<Transcoder> allTranscoders = new ArrayList<>();
5455
static final Map<String, Set<String>> allDirectTranscoderPaths = new HashMap<>();
5556

5657
static {
@@ -63,14 +64,25 @@ public class TranscodingManager {
6364

6465
if (TruffleOptions.AOT) {
6566
// Load the classes eagerly
66-
allTranscoders.add(e.getTranscoder());
67+
e.getTranscoder();
6768
}
6869

6970
allDirectTranscoderPaths.putIfAbsent(sourceName, new HashSet<>());
7071
final Set<String> fromSource = allDirectTranscoderPaths.get(sourceName);
7172
fromSource.add(destinationName);
7273
}
7374
}
75+
76+
if (TruffleOptions.AOT) {
77+
loadTablesEagerly();
78+
}
79+
}
80+
81+
private static void loadTablesEagerly() {
82+
for (UnicodeCodeRange unicodeCodeRange : UnicodeCodeRange.values()) {
83+
// To call package-private org.jcodings.unicode.UnicodeCodeRange#getRange()
84+
UnicodeEncoding.isInCodeRange(unicodeCodeRange, 0);
85+
}
7486
}
7587

7688
}

0 commit comments

Comments
 (0)