Skip to content

Commit 2f9fbb1

Browse files
committed
Bring back serialization string heap optimization
With a few tricks MoarVM can use the bytecode file's string heap for strings needed in deserialization, too. This avoids the need for setting up a string list in dependencies+deserialize.
1 parent fec8847 commit 2f9fbb1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/vm/moar/QAST/QASTCompilerMAST.nqp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,11 @@ my class MASTCompilerInstance {
869869
# This method is a hook point so that we can override serialization when cross-compiling
870870
method serialize_sc($sc) {
871871
my $sh := nqp::list_s();
872+
for $!mast_compunit.writer.string-heap.orig-strings {
873+
nqp::push_s($sh, $_);
874+
}
872875
my $serialized := nqp::serializetobuf($sc, $sh, MAST::Bytecode);
873-
[$serialized, $sh];
876+
[$serialized, $sh, 0]; # change to 1 when you need string heap deserialization
874877
}
875878

876879
method deserialization_code($sc, @code_ref_blocks, $repo_conf_res) {
@@ -884,7 +887,7 @@ my class MASTCompilerInstance {
884887
# String heap QAST.
885888
my $sh_ast;
886889

887-
if nqp::islist($sh) {
890+
if $sc_tuple[2] {
888891
$sh_ast := QAST::Op.new( :op('list_s') );
889892
my $sh_elems := nqp::elems($sh);
890893
my $i := 0;
@@ -2285,9 +2288,11 @@ my @kind_to_args := [0,
22852288

22862289
class MoarVM::StringHeap {
22872290
has @!strings;
2291+
has @!orig-strings;
22882292
has %!strings;
22892293
method BUILD(:@strings) {
22902294
@!strings := nqp::list();
2295+
@!orig-strings := nqp::list_s();
22912296
%!strings := nqp::hash();
22922297
if nqp::islist(@strings) {
22932298
for @strings {
@@ -2322,6 +2327,7 @@ class MoarVM::StringHeap {
23222327
$str.write_uint8(0) while $pad--;
23232328

23242329
nqp::push(@!strings, $str);
2330+
nqp::push_s(@!orig-strings, $s);
23252331

23262332
%!strings{$s} := nqp::elems(@!strings) - 1
23272333
}
@@ -2339,6 +2345,9 @@ class MoarVM::StringHeap {
23392345
method strings() {
23402346
@!strings
23412347
}
2348+
method orig-strings() {
2349+
@!orig-strings
2350+
}
23422351
}
23432352

23442353
sub align_section($size) {

0 commit comments

Comments
 (0)