Skip to content

Commit a116b22

Browse files
moste00eregon
authored andcommitted
made compact hashes the default, bucket hashes are strategy that require explicit config
1 parent 6a74271 commit a116b22

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

src/main/java/org/truffleruby/core/hash/HashLiteralNode.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.truffleruby.core.hash.library.EmptyHashStore;
1515
import org.truffleruby.core.hash.library.PackedHashStoreLibrary;
1616
import org.truffleruby.core.hash.library.PackedHashStoreLibraryFactory;
17+
import org.truffleruby.language.RubyBaseNode;
1718
import org.truffleruby.language.RubyContextSourceNode;
1819
import org.truffleruby.language.RubyNode;
1920

@@ -29,10 +30,14 @@ protected HashLiteralNode(RubyNode[] keyValues) {
2930
this.keyValues = keyValues;
3031
}
3132

32-
private static final boolean bigHashTypeIsCompactHash;
33-
static {
34-
String type = System.getProperty("BigHashStrategy");
35-
bigHashTypeIsCompactHash = type != null && type.equalsIgnoreCase("compact");
33+
public static final class BigHashConfiguredStrategy extends RubyBaseNode {
34+
private BigHashConfiguredStrategy() {
35+
isBuckets = getContext().getOptions().BIG_HASH_STRATEGY;
36+
}
37+
38+
// dummy instance, so we can call getContext instance method, never used
39+
private static final BigHashConfiguredStrategy bh = new BigHashConfiguredStrategy();
40+
public static boolean isBuckets;
3641
}
3742

3843
public static HashLiteralNode create(RubyNode[] keyValues) {
@@ -41,9 +46,9 @@ public static HashLiteralNode create(RubyNode[] keyValues) {
4146
} else if (keyValues.length <= PackedHashStoreLibrary.MAX_ENTRIES * 2) {
4247
return PackedHashStoreLibraryFactory.SmallHashLiteralNodeGen.create(keyValues);
4348
} else {
44-
return bigHashTypeIsCompactHash
45-
? new CompactHashStore.CompactHashLiteralNode(keyValues)
46-
: new BucketsHashStore.GenericHashLiteralNode(keyValues);
49+
return BigHashConfiguredStrategy.isBuckets
50+
? new BucketsHashStore.GenericHashLiteralNode(keyValues)
51+
: new CompactHashStore.CompactHashLiteralNode(keyValues);
4752
}
4853
}
4954

src/main/java/org/truffleruby/core/hash/library/PackedHashStoreLibrary.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ public final class PackedHashStoreLibrary {
6363
private static final int ELEMENTS_PER_ENTRY = 3;
6464
public static final int TOTAL_ELEMENTS = MAX_ENTRIES * ELEMENTS_PER_ENTRY;
6565

66-
private static final boolean bigHashTypeIsCompact;
67-
static {
68-
String hashType = System.getProperty("BigHashStrategy");
69-
bigHashTypeIsCompact = hashType != null && hashType.equalsIgnoreCase("compact");
70-
}
71-
7266
// region Utilities
7367

7468
public static Object[] createStore() {
@@ -241,14 +235,19 @@ static boolean set(Object[] store, RubyHash hash, Object key, Object value, bool
241235
return true;
242236
}
243237

244-
if (bigHashTypeIsCompact) {
245-
promoteToCompact(hash, store, size);
246-
} else {
247-
promoteToBuckets(hash, store, size);
248-
}
238+
promoteToBigHash(store, hash, size);
239+
249240
hashes.set(hash.store, hash, key2, value, byIdentity);
250241
return true;
251242
}
243+
244+
private static void promoteToBigHash(Object[] store, RubyHash hash, int size) {
245+
if (HashLiteralNode.BigHashConfiguredStrategy.isBuckets) {
246+
promoteToBuckets(hash, store, size);
247+
} else {
248+
promoteToCompact(hash, store, size);
249+
}
250+
}
252251
}
253252

254253
@ExportMessage

src/main/java/org/truffleruby/options/Options.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ public final class Options {
9393
public final boolean EXCEPTIONS_WARN_OUT_OF_MEMORY;
9494
/** --backtraces-interleave-java=false */
9595
public final boolean BACKTRACES_INTERLEAVE_JAVA;
96+
/** --buckets-big-hash=false */
97+
public final boolean BIG_HASH_STRATEGY;
9698
/** --backtraces-on-interrupt=false */
9799
public final boolean BACKTRACE_ON_INTERRUPT;
98100
/** --backtraces-sigalrm=!EMBEDDED */
@@ -247,6 +249,7 @@ public Options(Env env, OptionValues options, LanguageOptions languageOptions) {
247249
EXCEPTIONS_WARN_STACKOVERFLOW = options.get(OptionsCatalog.EXCEPTIONS_WARN_STACKOVERFLOW_KEY);
248250
EXCEPTIONS_WARN_OUT_OF_MEMORY = options.get(OptionsCatalog.EXCEPTIONS_WARN_OUT_OF_MEMORY_KEY);
249251
BACKTRACES_INTERLEAVE_JAVA = options.get(OptionsCatalog.BACKTRACES_INTERLEAVE_JAVA_KEY);
252+
BIG_HASH_STRATEGY = options.get(OptionsCatalog.BIG_HASH_STRATEGY_KEY);
250253
BACKTRACE_ON_INTERRUPT = options.get(OptionsCatalog.BACKTRACE_ON_INTERRUPT_KEY);
251254
BACKTRACE_ON_SIGALRM = options.hasBeenSet(OptionsCatalog.BACKTRACE_ON_SIGALRM_KEY) ? options.get(OptionsCatalog.BACKTRACE_ON_SIGALRM_KEY) : !EMBEDDED;
252255
BACKTRACE_ON_RAISE = options.get(OptionsCatalog.BACKTRACE_ON_RAISE_KEY);
@@ -378,6 +381,8 @@ public Object fromDescriptor(OptionDescriptor descriptor) {
378381
return EXCEPTIONS_WARN_OUT_OF_MEMORY;
379382
case "ruby.backtraces-interleave-java":
380383
return BACKTRACES_INTERLEAVE_JAVA;
384+
case "ruby.buckets-big-hash":
385+
return BIG_HASH_STRATEGY;
381386
case "ruby.backtraces-on-interrupt":
382387
return BACKTRACE_ON_INTERRUPT;
383388
case "ruby.backtraces-sigalrm":

src/options.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ EXPERT:
117117
EXCEPTIONS_WARN_OUT_OF_MEMORY: [exceptions-warn-out-of-memory, boolean, true, Warn when an out-of-memory error is thrown]
118118
BACKTRACES_INTERLEAVE_JAVA: [backtraces-interleave-java, boolean, false, Interleave Java stacktraces into the Ruby backtrace]
119119
BACKTRACES_OMIT_UNUSED: [backtraces-omit-unused, boolean, true, Omit backtraces that should be unused as they have pure rescue expressions]
120+
121+
# Big Hash Strategy
122+
BIG_HASH_STRATEGY: [buckets-big-hash, boolean, false, 'Whether to use chaining-style bukcets hash store for hash tables exceeding the small hash limit']
120123

121124
# Print backtraces at key events
122125
BACKTRACE_ON_INTERRUPT: [backtraces-on-interrupt, boolean, false, Show the backtraces of all Threads on Ctrl+C]

src/shared/java/org/truffleruby/shared/options/OptionsCatalog.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public final class OptionsCatalog {
6464
public static final OptionKey<Boolean> EXCEPTIONS_WARN_OUT_OF_MEMORY_KEY = new OptionKey<>(true);
6565
public static final OptionKey<Boolean> BACKTRACES_INTERLEAVE_JAVA_KEY = new OptionKey<>(false);
6666
public static final OptionKey<Boolean> BACKTRACES_OMIT_UNUSED_KEY = new OptionKey<>(true);
67+
public static final OptionKey<Boolean> BIG_HASH_STRATEGY_KEY = new OptionKey<>(false);
6768
public static final OptionKey<Boolean> BACKTRACE_ON_INTERRUPT_KEY = new OptionKey<>(false);
6869
public static final OptionKey<Boolean> BACKTRACE_ON_SIGALRM_KEY = new OptionKey<>(!EMBEDDED_KEY.getDefaultValue());
6970
public static final OptionKey<Boolean> BACKTRACE_ON_RAISE_KEY = new OptionKey<>(false);
@@ -519,6 +520,14 @@ public final class OptionsCatalog {
519520
.usageSyntax("")
520521
.build();
521522

523+
public static final OptionDescriptor BIG_HASH_STRATEGY = OptionDescriptor
524+
.newBuilder(BIG_HASH_STRATEGY_KEY, "ruby.buckets-big-hash")
525+
.help("Whether to use chaining-style bukcets hash store for hash tables exceeding the small hash limit")
526+
.category(OptionCategory.EXPERT)
527+
.stability(OptionStability.EXPERIMENTAL)
528+
.usageSyntax("")
529+
.build();
530+
522531
public static final OptionDescriptor BACKTRACE_ON_INTERRUPT = OptionDescriptor
523532
.newBuilder(BACKTRACE_ON_INTERRUPT_KEY, "ruby.backtraces-on-interrupt")
524533
.help("Show the backtraces of all Threads on Ctrl+C")
@@ -1425,6 +1434,8 @@ public static OptionDescriptor fromName(String name) {
14251434
return BACKTRACES_INTERLEAVE_JAVA;
14261435
case "ruby.backtraces-omit-unused":
14271436
return BACKTRACES_OMIT_UNUSED;
1437+
case "ruby.buckets-big-hash":
1438+
return BIG_HASH_STRATEGY;
14281439
case "ruby.backtraces-on-interrupt":
14291440
return BACKTRACE_ON_INTERRUPT;
14301441
case "ruby.backtraces-sigalrm":
@@ -1680,6 +1691,7 @@ public static OptionDescriptor[] allDescriptors() {
16801691
EXCEPTIONS_WARN_OUT_OF_MEMORY,
16811692
BACKTRACES_INTERLEAVE_JAVA,
16821693
BACKTRACES_OMIT_UNUSED,
1694+
BIG_HASH_STRATEGY,
16831695
BACKTRACE_ON_INTERRUPT,
16841696
BACKTRACE_ON_SIGALRM,
16851697
BACKTRACE_ON_RAISE,

0 commit comments

Comments
 (0)