Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use InternPool for all types and constant values #15569

Merged
merged 205 commits into from
Jun 13, 2023
Merged

Use InternPool for all types and constant values #15569

merged 205 commits into from
Jun 13, 2023

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented May 4, 2023

This changeset is centered around the InternPool data structure. Unfortunately, it required reworking a lot of compiler code.

The goal of this branch is to get to a mergeable state as soon as possible, so as to stop accumulating conflicts with master branch.

Follow-up enhancements will include:

  • Eliminating the legacy field from Value
  • Reworking the AIR encoding to take advantage of ability to reference constants via 32 bits. Perhaps Air.Inst.Ref can even store InternPool indexes directly, eliminating the AIR tags for constants.
  • Introducing garbage collection to the InternPool, perhaps in between incremental updates
  • Serialization and deserialization of the InternPool as part of incremental compilation
  • Audit all uses of val.toAllocatedBytes - likely each callsite can avoid a copy thanks to the intern pool.

/// This is handy if you have a u32 and want a u32 and don't want to take a
/// detour through many layers of abstraction elsewhere in the std.hash
/// namespace.
/// Copied from https://nullprogram.com/blog/2018/07/31/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This article was updated to point to skeeto/hash-prospector#19 for an improved function - skeeto/hash-prospector#19 (comment) or the previous comment on that issue seem to be the latest and greatest:

pub fn uint32(input: u32) u32 {
    var x: u32 = input;
    x ^= x >> 16;
    x *%= 0x21f0aaad;
    x ^= x >> 15;
    x *%= 0x735a2d97; // or 0xf35a2d97
    x ^= x >> 15;
    return x;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@andrewrk andrewrk force-pushed the intern-pool-3 branch 4 times, most recently from 1467d31 to 969ad6a Compare May 20, 2023 22:23
@andrewrk andrewrk changed the title Start using InternPool Use InternPool for all types and constant values May 31, 2023
@andrewrk andrewrk marked this pull request as ready for review June 3, 2023 00:36
@andrewrk andrewrk force-pushed the intern-pool-3 branch 2 times, most recently from 7c86b48 to dc15fa8 Compare June 10, 2023 23:43
@andrewrk andrewrk mentioned this pull request Jun 10, 2023
Instead of doing everything at once which is a hopelessly large task,
this introduces a piecemeal transition that can be done in small
increments at a time.

This is a minimal changeset that keeps the compiler compiling. It only
uses the InternPool for a small set of types.

Behavior tests are not passing.

Air.Inst.Ref and Zir.Inst.Ref are separated into different enums but
compile-time verified to have the same fields in the same order.

The large set of changes is mainly to deal with the fact that most Type
and Value methods now require a Module to be passed in, so that the
InternPool object can be accessed.
 * hashing
 * equality
 * encoding
This required additionally passing the `InternPool` into some AIR
methods.

Also, implement `Type.isNoReturn` for interned types.
jacobly0 and others added 10 commits June 11, 2023 03:01
Hopefully this also fixes the non-reproducing CI failures.
This avoids having dangling pointers into `InternPool.string_bytes`.
You must now write '_ = &f' rather than just '_ = f' to ensure a
function is compiled into a binary.
These are frequently invalidated whenever a string is interned, so avoid
creating pointers to `string_bytes` wherever possible.  This is an
attempt to fix random CI failures.
@andrewrk
Copy link
Member Author

andrewrk commented Jun 12, 2023

Here's a regression not covered by behavior tests:

$ git clone https://github.com/andrewrk/groovebasin
$ cd groovebasin
$ git checkout zig-pkg
$ zig build
Semantic Analysis [4986] thread 26462 panic: index out of bounds: index 1, len 1
Analyzing /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
      %508 = dbg_block_begin()
      %509 = dbg_stmt(3, 9)
      %510 = decl_val("putValue") 
      %511 = dbg_stmt(3, 21)
    > %512 = call(.auto, %510, [
        {
          %513 = break_inline(%512, %479)
        },
        {
          %514 = dbg_stmt(3, 33)
          %515 = field_val(%505, "name") 
          %516 = break_inline(%512, %515)
        },
        {
          %517 = dbg_stmt(3, 45)
          %518 = field_val(%505, "type") 
          %519 = break_inline(%512, %518)
        },
        {
          %520 = block_comptime({
            %521 = field_val(%505, "name") 
            %522 = break(%520, %521)
          }) 
          %523 = as_node(@InternPool.Index.slice_const_u8_type, %520) 
          %524 = field_val_named(%480, %523) 
          %525 = break_inline(%512, %524)
        },
      ]) 
      %526 = try(%512, {
        %527 = err_union_code(%512) 
        %528 = dbg_stmt(3, 9)
        %529 = ret_node(%527) 
      }) 
      %530 = ensure_result_used(%526) 
      %531 = dbg_block_end()
      %532 = restore_err_ret_index(%507, %4294967215)
      %533 = break(%507, @InternPool.Index.void_value)
    For full context, use the command
      zig ast-check -t /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig

  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
    > %507 = block({%508..%533}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
    > %499 = condbr_inline(%498, {%504..%535}, {%536}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
    > %500 = block_inline({%498, %499}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
    > %496 = block_inline({%497..%503}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValuesInner__anon_56581
    > %481 = block({%482..%540}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValues__anon_53462
    > %423 = is_non_err(%420) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValues__anon_53462
    > %425 = block({%418..%424}) 
  in /home/andy/dev/zig/lib/std/Build/Step/ConfigHeader.zig: Build/Step/ConfigHeader.zig:addValues__anon_53462
    > %414 = block({%415..%440}) 

/home/andy/dev/zig/src/Sema.zig:7851:25: 0x6e93c55 in resolveGenericInstantiationType (zig)
            generic_args[generic_arg_i] = arg_val.toIntern();
                        ^
/home/andy/dev/zig/src/Sema.zig:7547:62: 0x6ae83e0 in instantiateGenericCall (zig)
        const new_func = sema.resolveGenericInstantiationType(
                                                             ^
/home/andy/dev/zig/src/Sema.zig:6746:40: 0x66d5182 in analyzeCall (zig)
        if (sema.instantiateGenericCall(
                                       ^
/home/andy/dev/zig/src/Sema.zig:6553:32: 0x61d06d7 in zirCall__anon_130804 (zig)
        return sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, resolved_args, bound_arg_src, call_dbg_node);
                               ^
/home/andy/dev/zig/src/Sema.zig:951:62: 0x5f66fd7 in analyzeBodyInner (zig)
            .call                         => try sema.zirCall(block, inst, .direct),
                                                             ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:847:45: 0x5da5d81 in analyzeBodyBreak (zig)
    const break_inst = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                                            ^
/home/andy/dev/zig/src/Sema.zig:1645:62: 0x5f770b5 in analyzeBodyInner (zig)
                const break_data = (try sema.analyzeBodyBreak(block, inline_body)) orelse
                                                             ^
/home/andy/dev/zig/src/Sema.zig:847:45: 0x5da5d81 in analyzeBodyBreak (zig)
    const break_inst = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                                            ^
/home/andy/dev/zig/src/Sema.zig:1555:55: 0x5f759fa in analyzeBodyInner (zig)
                    break :b try sema.analyzeBodyBreak(&child_block, inline_body);
                                                      ^
/home/andy/dev/zig/src/Sema.zig:847:45: 0x5da5d81 in analyzeBodyBreak (zig)
    const break_inst = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                                            ^
/home/andy/dev/zig/src/Sema.zig:1555:55: 0x5f759fa in analyzeBodyInner (zig)
                    break :b try sema.analyzeBodyBreak(&child_block, inline_body);
                                                      ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:830:30: 0x6171fa8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/andy/dev/zig/src/Module.zig:5551:21: 0x5f495dc in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/Module.zig:4149:40: 0x5d85c29 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/andy/dev/zig/src/Sema.zig:29751:36: 0x67afb16 in ensureFuncBodyAnalyzed (zig)
    sema.mod.ensureFuncBodyAnalyzed(func) catch |err| {
                                   ^
/home/andy/dev/zig/src/Sema.zig:32643:40: 0x62ddd41 in resolveInferredErrorSet (zig)
        try sema.ensureFuncBodyAnalyzed(ies.func);
                                       ^
/home/andy/dev/zig/src/Sema.zig:30076:53: 0x62ac333 in analyzeIsNonErrComptimeOnly (zig)
                    try sema.resolveInferredErrorSet(block, src, ies_index);
                                                    ^
/home/andy/dev/zig/src/Sema.zig:30104:56: 0x66f297c in analyzeIsNonErr (zig)
    const result = try sema.analyzeIsNonErrComptimeOnly(block, src, operand);
                                                       ^
/home/andy/dev/zig/src/Sema.zig:17385:32: 0x61e2886 in zirIsNonErr (zig)
    return sema.analyzeIsNonErr(block, src, operand);
                               ^
/home/andy/dev/zig/src/Sema.zig:994:66: 0x5f691f6 in analyzeBodyInner (zig)
            .is_non_err                   => try sema.zirIsNonErr(block, inst),
                                                                 ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:830:30: 0x6171fa8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/andy/dev/zig/src/Module.zig:5551:21: 0x5f495dc in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/Module.zig:4149:40: 0x5d85c29 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/andy/dev/zig/src/Compilation.zig:3143:42: 0x5d83c09 in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/andy/dev/zig/src/Compilation.zig:3080:30: 0x5c25fbe in performAllTheWork (zig)
            try processOneJob(comp, work_item, main_progress_node);
                             ^
/home/andy/dev/zig/src/Compilation.zig:2029:31: 0x5c22668 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/andy/dev/zig/src/main.zig:3840:24: 0x5c4fd5a in updateModule (zig)
        try comp.update(main_progress_node);
                       ^
/home/andy/dev/zig/src/main.zig:4479:21: 0x5ae2075 in cmdBuild (zig)
        updateModule(comp) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/main.zig:285:24: 0x5a8cab8 in mainArgs (zig)
        return cmdBuild(gpa, arena, cmd_args);
                       ^
/home/andy/dev/zig/src/main.zig:213:20: 0x5a89a05 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/andy/dev/zig/lib/std/start.zig:609:37: 0x5a89488 in main (zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7ff2cc27b24d in ??? (???)
???:?:?: 0x7fffedf484fa in ??? (???)
fish: Job 1, '~/dev/zig/build-release/stage4/…' terminated by signal SIGABRT (Abort)

@andrewrk
Copy link
Member Author

Another one. Unfortunately requires git lfs to reproduce:

# install git lfs and then
$ git clone https://github.com/MasonRemaley/2Pew
$ cd 2Pew
$ zig build -Dtarget=x86_64-windows
zig build-exe bench Debug x86_64-windows: error: the following command failed with 2 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig build-exe /home/andy/dev/2Pew/src/bench.zig --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name bench -target x86_64-windows -mcpu x86_64 --listen=- 
zig build-exe pew Debug x86_64-windows: error: the following command failed with 1 compilation errors:
/home/andy/dev/zig/build-release/stage4/bin/zig build-exe /home/andy/dev/2Pew/src/main.zig /home/andy/dev/2Pew/zig-cache/o/5f5575db6ef66c3951b81d43b0f46d99/SDL2.lib -lsetupapi -lwinmm -lgdi32 -limm32 -lversion -loleaut32 -lole32 -cflags -std=c99 -- /home/andy/dev/2Pew/src/stb_image.c -lc --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name pew -target x86_64-windows -mcpu x86_64 -I /home/andy/dev/2Pew/zig-cache/i/ab8a6117e3562fb473fc4b5cad8c7c36/include -I /home/andy/dev/2Pew/src -fno-lto --listen=- 
Build Summary: 3/8 steps succeeded; 2 failed (disable with -fno-summary)
install transitive failure
├─ install data/ cached
├─ install pew transitive failure
│  └─ zig build-exe pew Debug x86_64-windows 1 errors
│     ├─ zig build-lib SDL2 ReleaseFast x86_64-windows success 15s MaxRSS:171M
│     └─ install include/ success
└─ install bench transitive failure
   └─ zig build-exe bench Debug x86_64-windows 2 errors
src/ecs/entities.zig:389:20: error: comptime dereference requires '??slot_map.Handle(1000000,u32)' to have a well-defined layout, but it does not.
            return @Type(Type{
                   ^~~~~
src/ecs/entities.zig:250:46: note: called from here
        pub const PrefabEntity = ComponentMap(.Auto, struct {
                                 ~~~~~~~~~~~~^
src/ecs/entities.zig:389:20: error: comptime dereference requires '?ecs.entities.Entities(.{.x = u128, .y = u256, .z = u128}).IteratorComponentDescriptor' to have a well-defined layout, but it does not.
            return @Type(Type{
                   ^~~~~
src/ecs/entities.zig:409:52: note: called from here
        pub const IteratorDescriptor = ComponentMap(.Auto, struct {
                                       ~~~~~~~~~~~~^
src/ecs/entities.zig:389:20: error: comptime dereference requires '?u128' to have a well-defined layout, but it does not.
            return @Type(Type{
                   ^~~~~
src/ecs/entities.zig:250:46: note: called from here
        pub const PrefabEntity = ComponentMap(.Auto, struct {
                                 ~~~~~~~~~~~~^

@andrewrk
Copy link
Member Author

Another one:

$ git clone https://github.com/thejoshwolfe/legend-of-swarkland
$ cd legend-of-swarkland
$ zig build -Dtarget=x86_64-windows
zig build-exe legend-of-swarkland_headless Debug x86_64-windows: error: thread 42667 panic: switch on corrupt value
Analyzing src/server/map_gen.zig: map_gen.zig:generatePuzzleLevels
      %6520 = dbg_block_begin()
      %6521 = dbg_stmt(2, 5)
      %6522 = decl_val("buildTheTerrain") 
      %6523 = dbg_stmt(2, 24)
      %6524 = call(.auto, %6522, [
        {
          %6525 = ref(%6518) 
          %6526 = dbg_stmt(2, 36)
          %6527 = field_ptr(%6525, "terrain") 
          %6528 = break_inline(%6524, %6527)
        },
      ]) 
    > %6529 = try(%6524, {
        %6530 = err_union_code(%6524) 
        %6531 = dbg_stmt(2, 5)
        %6532 = ret_node(%6530) 
      }) 
      %6533 = ensure_result_used(%6529) 
      %6534 = dbg_stmt(7, 5)
      %6535 = alloc_mut(@InternPool.Index.u32_type) 
      %6536 = int(2)
      %6537 = store_node(%6535, %6536) 
      %6538 = dbg_var_ptr(%6535, "non_human_id_cursor")
      %6539 = dbg_stmt(8, 5)
      %6540 = alloc_inferred_mut() 
      %6541 = store_to_inferred_ptr(%6540, @InternPool.Index.bool_false)
      %6542 = resolve_inferred_alloc(%6540) 
      %6543 = dbg_var_ptr(%6540, "found_human")
      %6544 = dbg_stmt(9, 5)
      %6545 = dbg_var_val(@InternPool.Index.zero, "level_x")
      %6546 = alloc(@InternPool.Index.usize_type) 
      %6547 = store(%6546, @InternPool.Index.zero_usize)
      %6548 = dbg_stmt(10, 10)
      %6549 = decl_val("the_levels") 
      %6550 = as_node(@InternPool.Index.usize_type, @InternPool.Index.zero) 
      %6551 = dbg_stmt(10, 20)
      %6552 = elem_val_node(%6549, %6550) 
      %6553 = dbg_stmt(10, 23)
      %6554 = field_val(%6552, "individuals") 
      %6555 = for_len({%6554}) 
      %6556 = loop({
        %6557 = load(%6546) 
        %6560 = block({
          %6558 = cmp_lt(%6557, %6555) 
          %6559 = condbr(%6558, {
            %6564 = dbg_block_begin()
            %6565 = elem_val(%6554, %6557) 
            %6572 = ref(%6565) 
            %6566 = dbg_var_val(%6565, "_individual")
            %6567 = block({
              %6568 = dbg_block_begin()
              %6569 = dbg_stmt(11, 9)
              %6571 = dbg_stmt(11, 28)
              %6573 = dbg_stmt(11, 43)
              %6574 = dbg_stmt(11, 49)
              %6575 = field_call(.auto, %6572, "clone", [
                {
                  %6576 = dbg_stmt(11, 60)
                  %6577 = field_val(%6518, "allocator") 
                  %6578 = break_inline(%6575, %6577)
                },
              ]) 
              %6579 = try(%6575, {
                %6580 = err_union_code(%6575) 
                %6581 = dbg_stmt(11, 28)
                %6582 = ret_node(%6580) 
              }) 
              %6587 = ref(%6579) 
              %6584 = save_err_ret_index(%6579)
              %6585 = dbg_var_val(%6579, "individual")
              %6586 = dbg_stmt(12, 9)
              %6588 = dbg_stmt(12, 19)
              %6589 = field_ptr(%6587, "abs_position") 
              %6590 = decl_ref("core") 
              %6591 = dbg_stmt(12, 39)
              %6592 = field_ptr(%6590, "game_logic") 
              %6593 = dbg_stmt(12, 50)
              %6594 = dbg_stmt(12, 65)
              %6595 = field_call(.auto, %6592, "offsetPosition", [
                {
                  %6596 = dbg_stmt(12, 76)
                  %6597 = field_val(%6579, "abs_position") 
                  %6598 = break_inline(%6595, %6597)
                },
                {
                  %6599 = decl_val("makeCoord") 
                  %6600 = dbg_stmt(12, 100)
                  %6601 = call(.auto, %6599, [
                    {
                      %6602 = break_inline(%6601, @InternPool.Index.zero)
                    },
                    {
                      %6603 = break_inline(%6601, @InternPool.Index.zero)
                    },
                  ]) 
                  %6604 = break_inline(%6595, %6601)
                },
              ]) 
              %6605 = store_node(%6589, %6595) 
              %6606 = dbg_stmt(14, 9)
              %6607 = alloc_mut(@InternPool.Index.u32_type) 
              %6608 = store_node(%6607, @InternPool.Index.undef) 
              %6609 = dbg_var_ptr(%6607, "id")
              %6610 = dbg_stmt(15, 13)
              %6617 = block({
                %6611 = dbg_stmt(15, 23)
                %6612 = field_val(%6579, "species") 
                %6613 = enum_literal("human") 
                %6614 = cmp_eq(%6612, %6613) 
                %6615 = as_node(@InternPool.Index.bool_type, %6614) 
                %6616 = condbr(%6615, {
                  %6618 = dbg_block_begin()
                  %6619 = block({
                    %6620 = dbg_block_begin()
                    %6621 = dbg_stmt(16, 13)
                    %6622 = store_node(%6607, @InternPool.Index.one) 
                    %6623 = dbg_stmt(17, 13)
                    %6624 = store_node(%6540, @InternPool.Index.bool_true) 
                    %6625 = dbg_block_end()
                    %6626 = restore_err_ret_index(%6619, %4294967215)
                    %6627 = break(%6619, @InternPool.Index.void_value)
                  }) 
                  %6628 = dbg_block_end()
                  %6645 = break(%6617, @InternPool.Index.void_value)
                }, {
                  %6629 = dbg_block_begin()
                  %6630 = block({
                    %6631 = dbg_block_begin()
                    %6632 = dbg_stmt(19, 13)
                    %6633 = load(%6535) 
                    %6634 = store_node(%6607, %6633) 
                    %6635 = dbg_stmt(20, 13)
                    %6636 = load(%6535) 
                    %6637 = typeof(%6636) 
                    %6638 = dbg_stmt(20, 33)
                    %6639 = add(%6636, @InternPool.Index.one) 
                    %6640 = store(%6535, %6639)
                    %6641 = dbg_block_end()
                    %6642 = restore_err_ret_index(%6630, %4294967215)
                    %6643 = break(%6630, @InternPool.Index.void_value)
                  }) 
                  %6644 = dbg_block_end()
                  %6646 = break(%6617, @InternPool.Index.void_value)
                }) 
              }) 
              %6647 = ensure_result_used(%6617) 
              %6648 = dbg_stmt(22, 9)
              %6649 = ref(%6518) 
              %6650 = dbg_stmt(22, 23)
              %6651 = field_ptr(%6649, "individuals") 
              %6652 = dbg_stmt(22, 35)
              %6653 = dbg_stmt(22, 48)
              %6654 = field_call(.auto, %6651, "putNoClobber", [
                {
                  %6655 = load(%6607) 
                  %6656 = break_inline(%6654, %6655)
                },
                {
                  %6657 = break_inline(%6654, %6579)
                },
              ]) 
              %6658 = try(%6654, {
                %6659 = err_union_code(%6654) 
                %6660 = dbg_stmt(22, 9)
                %6661 = ret_node(%6659) 
              }) 
              %6662 = ensure_result_used(%6658) 
              %6663 = dbg_block_end()
              %6664 = restore_err_ret_index(%6567, %4294967215)
              %6665 = break(%6567, @InternPool.Index.void_value)
            }) 
            %6666 = dbg_block_end()
            %6667 = break(%6560, @InternPool.Index.void_value)
          }, {
            %6668 = break(%6556, @InternPool.Index.void_value)
          }) 
        }) 
        %6561 = add_unsafe(%6557, @InternPool.Index.one_usize) 
        %6562 = store(%6546, %6561)
        %6563 = repeat() 
      }) 
      %6669 = ensure_result_used(%6556) 
      %6670 = dbg_stmt(24, 5)
      %6671 = decl_ref("std") 
      %6672 = dbg_stmt(24, 8)
      %6673 = field_ptr(%6671, "debug") 
      %6674 = dbg_stmt(24, 14)
      %6675 = dbg_stmt(24, 21)
      %6676 = field_call(nodiscard .auto, %6673, "assert", [
        {
          %6677 = load(%6540) 
          %6678 = break_inline(%6676, %6677)
        },
      ]) 
      %6679 = dbg_block_end()
      %6680 = restore_err_ret_index(%6519, %4294967215)
      %6681 = break(%6519, @InternPool.Index.void_value)
    For full context, use the command
      zig ast-check -t src/server/map_gen.zig

  in src/server/map_gen.zig: map_gen.zig:generatePuzzleLevels
    > %6519 = block({%6520..%6681}) 
  in src/server/game_model.zig: game_model.zig:GameState.generate
    > %427 = try(%424, {%428..%430}) 
  in src/server/game_model.zig: game_model.zig:GameState.generate
    > %345 = block({%346..%440}) 
  in src/server/game_server.zig: game_server.zig:server_main
    > %221 = try(%216, {%222..%224}) 
  in src/server/game_server.zig: game_server.zig:server_main
    > %93 = block({%94..%1163}) 

/home/andy/dev/zig/src/value.zig:359:17: 0x5da6e8f in intern (zig)
        switch (val.tag()) {
                ^
/home/andy/dev/zig/src/Module.zig:876:40: 0x5da62ca in intern (zig)
        decl.val = (try decl.val.intern(decl.ty, mod)).toValue();
                                       ^
/home/andy/dev/zig/src/Module.zig:6560:20: 0x5d94a98 in markDeclAlive (zig)
    try decl.intern(mod);
                   ^
/home/andy/dev/zig/src/codegen/llvm.zig:4012:30: 0x5fccb36 in lowerDeclRefValue (zig)
        try mod.markDeclAlive(decl);
                             ^
/home/andy/dev/zig/src/codegen/llvm.zig:3389:69: 0x5ddacd9 in lowerValue (zig)
                    .mut_decl => |mut_decl| try dg.lowerDeclRefValue(ptr_tv, mut_decl.decl),
                                                                    ^
/home/andy/dev/zig/src/codegen/llvm.zig:3663:65: 0x5dde860 in lowerValue (zig)
                        const field_llvm_val = try dg.lowerValue(.{
                                                                ^
/home/andy/dev/zig/src/codegen/llvm.zig:3458:62: 0x5ddbdb8 in lowerValue (zig)
                            llvm_elems[i] = try dg.lowerValue(.{ .ty = elem_ty, .val = elem_val.toValue() });
                                                             ^
/home/andy/dev/zig/src/codegen/llvm.zig:4290:48: 0x6637f9c in resolveValue (zig)
        const llvm_val = try self.dg.lowerValue(tv);
                                               ^
/home/andy/dev/zig/src/codegen/llvm.zig:4280:47: 0x6638565 in resolveInst (zig)
        const llvm_val = try self.resolveValue(.{
                                              ^
/home/andy/dev/zig/src/codegen/llvm.zig:5663:52: 0x668a2b8 in airArrayElemVal (zig)
        const array_llvm_val = try self.resolveInst(bin_op.lhs);
                                                   ^
/home/andy/dev/zig/src/codegen/llvm.zig:4506:64: 0x618e840 in genBody (zig)
                .array_elem_val     => try self.airArrayElemVal(body[i..]),
                                                               ^
/home/andy/dev/zig/src/codegen/llvm.zig:5260:25: 0x665e77e in airCondBr (zig)
        try self.genBody(then_body);
                        ^
/home/andy/dev/zig/src/codegen/llvm.zig:4428:54: 0x618c01f in genBody (zig)
                .cond_br        => try self.airCondBr(inst),
                                                     ^
/home/andy/dev/zig/src/codegen/llvm.zig:5196:25: 0x665b6af in airBlock (zig)
        try self.genBody(body);
                        ^
/home/andy/dev/zig/src/codegen/llvm.zig:4421:53: 0x618bce6 in genBody (zig)
                .block          => try self.airBlock(inst),
                                                    ^
/home/andy/dev/zig/src/codegen/llvm.zig:5423:25: 0x66637f1 in airLoop (zig)
        try self.genBody(body);
                        ^
/home/andy/dev/zig/src/codegen/llvm.zig:4437:52: 0x618c6a6 in genBody (zig)
                .loop           => try self.airLoop(inst),
                                                   ^
/home/andy/dev/zig/src/codegen/llvm.zig:5196:25: 0x665b6af in airBlock (zig)
        try self.genBody(body);
                        ^
/home/andy/dev/zig/src/codegen/llvm.zig:4421:53: 0x618bce6 in genBody (zig)
                .block          => try self.airBlock(inst),
                                                    ^
/home/andy/dev/zig/src/codegen/llvm.zig:1215:19: 0x618774b in updateFunc (zig)
        fg.genBody(air.getMainBody()) catch |err| switch (err) {
                  ^
/home/andy/dev/zig/src/link/Coff.zig:1041:42: 0x6184067 in updateFunc (zig)
            return llvm_object.updateFunc(mod, func_index, air, liveness);
                                         ^
/home/andy/dev/zig/src/link.zig:572:77: 0x5f4b419 in updateFunc (zig)
            .elf   => return @fieldParentPtr(Elf,   "base", base).updateFunc(module, func_index, air, liveness),
                                                                            ^
/home/andy/dev/zig/src/Module.zig:4215:37: 0x5d8662a in ensureFuncBodyAnalyzed (zig)
            comp.bin_file.updateFunc(mod, func_index, air, liveness) catch |err| switch (err) {
                                    ^
/home/andy/dev/zig/src/Sema.zig:29751:36: 0x67afb16 in ensureFuncBodyAnalyzed (zig)
    sema.mod.ensureFuncBodyAnalyzed(func) catch |err| {
                                   ^
/home/andy/dev/zig/src/Sema.zig:32643:40: 0x62ddd41 in resolveInferredErrorSet (zig)
        try sema.ensureFuncBodyAnalyzed(ies.func);
                                       ^
/home/andy/dev/zig/src/Sema.zig:30076:53: 0x62ac333 in analyzeIsNonErrComptimeOnly (zig)
                    try sema.resolveInferredErrorSet(block, src, ies_index);
                                                    ^
/home/andy/dev/zig/src/Sema.zig:17501:60: 0x62ab160 in zirTry (zig)
    const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);
                                                           ^
/home/andy/dev/zig/src/Sema.zig:1654:67: 0x5f7738b in analyzeBodyInner (zig)
                if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
                                                                  ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:830:30: 0x6171fa8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/andy/dev/zig/src/Module.zig:5551:21: 0x5f495dc in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/Module.zig:4149:40: 0x5d85c29 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/andy/dev/zig/src/Sema.zig:29751:36: 0x67afb16 in ensureFuncBodyAnalyzed (zig)
    sema.mod.ensureFuncBodyAnalyzed(func) catch |err| {
                                   ^
/home/andy/dev/zig/src/Sema.zig:32643:40: 0x62ddd41 in resolveInferredErrorSet (zig)
        try sema.ensureFuncBodyAnalyzed(ies.func);
                                       ^
/home/andy/dev/zig/src/Sema.zig:32650:41: 0x62dde3d in resolveInferredErrorSet (zig)
        try sema.resolveInferredErrorSet(block, src, other_ies_index);
                                        ^
/home/andy/dev/zig/src/Sema.zig:30076:53: 0x62ac333 in analyzeIsNonErrComptimeOnly (zig)
                    try sema.resolveInferredErrorSet(block, src, ies_index);
                                                    ^
/home/andy/dev/zig/src/Sema.zig:17501:60: 0x62ab160 in zirTry (zig)
    const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);
                                                           ^
/home/andy/dev/zig/src/Sema.zig:1654:67: 0x5f7738b in analyzeBodyInner (zig)
                if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
                                                                  ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:830:30: 0x6171fa8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/andy/dev/zig/src/Module.zig:5551:21: 0x5f495dc in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/Module.zig:4149:40: 0x5d85c29 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/andy/dev/zig/src/Sema.zig:29751:36: 0x67afb16 in ensureFuncBodyAnalyzed (zig)
    sema.mod.ensureFuncBodyAnalyzed(func) catch |err| {
                                   ^
/home/andy/dev/zig/src/Sema.zig:32643:40: 0x62ddd41 in resolveInferredErrorSet (zig)
        try sema.ensureFuncBodyAnalyzed(ies.func);
                                       ^
/home/andy/dev/zig/src/Sema.zig:30076:53: 0x62ac333 in analyzeIsNonErrComptimeOnly (zig)
                    try sema.resolveInferredErrorSet(block, src, ies_index);
                                                    ^
/home/andy/dev/zig/src/Sema.zig:17501:60: 0x62ab160 in zirTry (zig)
    const is_non_err = try sema.analyzeIsNonErrComptimeOnly(parent_block, operand_src, err_union);
                                                           ^
/home/andy/dev/zig/src/Sema.zig:1654:67: 0x5f7738b in analyzeBodyInner (zig)
                if (!block.is_comptime) break :blk try sema.zirTry(block, inst);
                                                                  ^
/home/andy/dev/zig/src/Sema.zig:5645:34: 0x6718279 in resolveBlockBody (zig)
        if (sema.analyzeBodyInner(child_block, body)) |_| {
                                 ^
/home/andy/dev/zig/src/Sema.zig:5628:33: 0x62afd0e in zirBlock (zig)
    return sema.resolveBlockBody(parent_block, src, &child_block, body, inst, &label.merges);
                                ^
/home/andy/dev/zig/src/Sema.zig:1499:49: 0x5f79184 in analyzeBodyInner (zig)
                    break :blk try sema.zirBlock(block, inst, tags[inst] == .block_comptime);
                                                ^
/home/andy/dev/zig/src/Sema.zig:830:30: 0x6171fa8 in analyzeBody (zig)
    _ = sema.analyzeBodyInner(block, body) catch |err| switch (err) {
                             ^
/home/andy/dev/zig/src/Module.zig:5551:21: 0x5f495dc in analyzeFnBody (zig)
    sema.analyzeBody(&inner_block, fn_info.body) catch |err| switch (err) {
                    ^
/home/andy/dev/zig/src/Module.zig:4149:40: 0x5d85c29 in ensureFuncBodyAnalyzed (zig)
            var air = mod.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
                                       ^
/home/andy/dev/zig/src/Compilation.zig:3143:42: 0x5d83c09 in processOneJob (zig)
            module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
                                         ^
/home/andy/dev/zig/src/Compilation.zig:3080:30: 0x5c25fbe in performAllTheWork (zig)
            try processOneJob(comp, work_item, main_progress_node);
                             ^
/home/andy/dev/zig/src/Compilation.zig:2029:31: 0x5c22668 in update (zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/home/andy/dev/zig/src/main.zig:3418:36: 0x5c4e388 in serve (zig)
                    try comp.update(main_progress_node);
                                   ^
/home/andy/dev/zig/src/main.zig:3232:22: 0x5ad7f5a in buildOutputType (zig)
            try serve(
                     ^
/home/andy/dev/zig/src/main.zig:269:31: 0x5a8c4a1 in mainArgs (zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });
                              ^
/home/andy/dev/zig/src/main.zig:213:20: 0x5a89a05 in main (zig)
    return mainArgs(gpa, arena, args);
                   ^
/home/andy/dev/zig/lib/std/start.zig:609:37: 0x5a89488 in main (zig)
            const result = root.main() catch |err| {
                                    ^

@andrewrk
Copy link
Member Author

andrewrk commented Jun 13, 2023

perf data point on 2pew:

  • intern-pool-3 maxrss: 226 MiB
  • master maxrss: 218 MiB
Benchmark 1: master/build-release/stage3/bin/zig build-exe /home/andy/dev/2Pew/src/main.zig -lSDL2 -cflags -std=c99 -- /home/andy/dev/2Pew/src/stb_image.c -lc --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name pew -I /home/andy/dev/2Pew/src -fno-lto
  Time (mean ± σ):      2.098 s ±  0.039 s    [User: 2.071 s, System: 0.120 s]
  Range (min … max):    2.038 s …  2.151 s    10 runs
 
Benchmark 2: intern-pool-3/build-release/stage3/bin/zig build-exe /home/andy/dev/2Pew/src/main.zig -lSDL2 -cflags -std=c99 -- /home/andy/dev/2Pew/src/stb_image.c -lc --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name pew -I /home/andy/dev/2Pew/src -fno-lto
  Time (mean ± σ):      2.190 s ±  0.029 s    [User: 2.131 s, System: 0.121 s]
  Range (min … max):    2.137 s …  2.249 s    10 runs
 
Summary
  'master/build-release/stage3/bin/zig build-exe /home/andy/dev/2Pew/src/main.zig -lSDL2 -cflags -std=c99 -- /home/andy/dev/2Pew/src/stb_image.c -lc --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name pew -I /home/andy/dev/2Pew/src -fno-lto' ran
    1.04 ± 0.02 times faster than 'intern-pool-3/build-release/stage3/bin/zig build-exe /home/andy/dev/2Pew/src/main.zig -lSDL2 -cflags -std=c99 -- /home/andy/dev/2Pew/src/stb_image.c -lc --cache-dir /home/andy/dev/2Pew/zig-cache --global-cache-dir /home/andy/.cache/zig --name pew -I /home/andy/dev/2Pew/src -fno-lto'

@andrewrk
Copy link
Member Author

perf data point for ghostty:

  • intern-pool-3 maxrss: 463 MiB
  • master maxrss: 1130 MiB
Benchmark 1: intern-pool-3
  Time (mean ± σ):      5.893 s ±  0.139 s    [User: 5.718 s, System: 0.364 s]
  Range (min … max):    5.666 s …  6.139 s    10 runs
 
Benchmark 2: master
  Time (mean ± σ):      6.264 s ±  0.107 s    [User: 5.933 s, System: 0.551 s]
  Range (min … max):    6.156 s …  6.473 s    10 runs
 
Summary
  'intern-pool-3' ran
    1.06 ± 0.03 times faster than 'master'

jacobly0 and others added 3 commits June 12, 2023 18:24
By correctly handling comptime-only types appearing in non-comptime
parameters (when the parameter is either anytype or generic), this
avoids an index out of bounds later when later filling out
`monomorphed_args` using what used to be slightly different logic.
@andrewrk
Copy link
Member Author

perf data point for legend-of-swarkland:

peak rss:

  • intern-pool-3: 395 MiB
  • master: 407 MiB

perf:

Benchmark 1: master/bin/zig build-exe /home/andy/dev/legend-of-swarkland/src/gui/gui_main.zig -lSDL2 -lc --cache-dir /home/andy/dev/legend-of-swarkland/zig-cache --global-cache-dir /home/andy/.cache/zig --name legend-of-swarkland --mod fonts6x10:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/be8699e7ebdd2b68b671237ae38750b0/fontsheet6x10.zig --mod core::/home/andy/dev/legend-of-swarkland/src/index.zig --mod fonts12x16:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/801425a37f8312a2b0e1d1b2afb4c3aa/fontsheet12x16.zig --mod large_sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/7a846e2ca2a010e8e55bd312f9aca74c/spritesheet200.zig --mod config::/home/andy/dev/legend-of-swarkland/zig-cache/c/e198c4b3893804a7c61da8957460d4ae/options.zig --mod sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/81c31dd7e517aa37226d96b879bd6fe9/spritesheet32.zig --mod server:core:/home/andy/dev/legend-of-swarkland/src/server/game_server.zig --mod client:core,server:/home/andy/dev/legend-of-swarkland/src/client/main.zig --deps core,server,client,sprites,large_sprites,fonts12x16,fonts6x10,config
  Time (mean ± σ):      4.642 s ±  0.095 s    [User: 4.509 s, System: 0.218 s]
  Range (min … max):    4.516 s …  4.775 s    10 runs
 
Benchmark 2: intern-pool-3/bin/zig build-exe /home/andy/dev/legend-of-swarkland/src/gui/gui_main.zig -lSDL2 -lc --cache-dir /home/andy/dev/legend-of-swarkland/zig-cache --global-cache-dir /home/andy/.cache/zig --name legend-of-swarkland --mod fonts6x10:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/be8699e7ebdd2b68b671237ae38750b0/fontsheet6x10.zig --mod core::/home/andy/dev/legend-of-swarkland/src/index.zig --mod fonts12x16:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/801425a37f8312a2b0e1d1b2afb4c3aa/fontsheet12x16.zig --mod large_sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/7a846e2ca2a010e8e55bd312f9aca74c/spritesheet200.zig --mod config::/home/andy/dev/legend-of-swarkland/zig-cache/c/e198c4b3893804a7c61da8957460d4ae/options.zig --mod sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/81c31dd7e517aa37226d96b879bd6fe9/spritesheet32.zig --mod server:core:/home/andy/dev/legend-of-swarkland/src/server/game_server.zig --mod client:core,server:/home/andy/dev/legend-of-swarkland/src/client/main.zig --deps core,server,client,sprites,large_sprites,fonts12x16,fonts6x10,config
  Time (mean ± σ):      4.600 s ±  0.155 s    [User: 4.450 s, System: 0.204 s]
  Range (min … max):    4.388 s …  4.846 s    10 runs
 
Summary
  'intern-pool-3/bin/zig build-exe /home/andy/dev/legend-of-swarkland/src/gui/gui_main.zig -lSDL2 -lc --cache-dir /home/andy/dev/legend-of-swarkland/zig-cache --global-cache-dir /home/andy/.cache/zig --name legend-of-swarkland --mod fonts6x10:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/be8699e7ebdd2b68b671237ae38750b0/fontsheet6x10.zig --mod core::/home/andy/dev/legend-of-swarkland/src/index.zig --mod fonts12x16:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/801425a37f8312a2b0e1d1b2afb4c3aa/fontsheet12x16.zig --mod large_sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/7a846e2ca2a010e8e55bd312f9aca74c/spritesheet200.zig --mod config::/home/andy/dev/legend-of-swarkland/zig-cache/c/e198c4b3893804a7c61da8957460d4ae/options.zig --mod sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/81c31dd7e517aa37226d96b879bd6fe9/spritesheet32.zig --mod server:core:/home/andy/dev/legend-of-swarkland/src/server/game_server.zig --mod client:core,server:/home/andy/dev/legend-of-swarkland/src/client/main.zig --deps core,server,client,sprites,large_sprites,fonts12x16,fonts6x10,config' ran
    1.01 ± 0.04 times faster than 'master/bin/zig build-exe /home/andy/dev/legend-of-swarkland/src/gui/gui_main.zig -lSDL2 -lc --cache-dir /home/andy/dev/legend-of-swarkland/zig-cache --global-cache-dir /home/andy/.cache/zig --name legend-of-swarkland --mod fonts6x10:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/be8699e7ebdd2b68b671237ae38750b0/fontsheet6x10.zig --mod core::/home/andy/dev/legend-of-swarkland/src/index.zig --mod fonts12x16:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/801425a37f8312a2b0e1d1b2afb4c3aa/fontsheet12x16.zig --mod large_sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/7a846e2ca2a010e8e55bd312f9aca74c/spritesheet200.zig --mod config::/home/andy/dev/legend-of-swarkland/zig-cache/c/e198c4b3893804a7c61da8957460d4ae/options.zig --mod sprites:core:/home/andy/dev/legend-of-swarkland/zig-cache/o/81c31dd7e517aa37226d96b879bd6fe9/spritesheet32.zig --mod server:core:/home/andy/dev/legend-of-swarkland/src/server/game_server.zig --mod client:core,server:/home/andy/dev/legend-of-swarkland/src/client/main.zig --deps core,server,client,sprites,large_sprites,fonts12x16,fonts6x10,config'

Long term, linker backends will need to manage their own string tables
for things like this because my mandate is: no long-lived pointers
allowed in any of the codepaths touched by incremental compilation, so
that we can serialize and deserialize trivially.

Short term, I solved this with a couple calls to Allocator.dupe,
incurring some harmless leaks.
@andrewrk
Copy link
Member Author

perf data point for groove basin:

peak RSS:

  • master: 431 MiB
  • intern-pool-3: 431 MiB
Benchmark 1: master/stage3/bin/zig build-exe /home/andy/dev/groovebasin/src/server/server_main.zig ...
  Time (mean ± σ):      2.581 s ±  0.024 s    [User: 2.583 s, System: 0.458 s]
  Range (min … max):    2.555 s …  2.622 s    10 runs
 
Benchmark 2: intern-pool-3/stage3/bin/zig build-exe /home/andy/dev/groovebasin/src/server/server_main.zig ...
  Time (mean ± σ):      2.860 s ±  0.080 s    [User: 2.834 s, System: 0.458 s]
  Range (min … max):    2.742 s …  3.000 s    10 runs
 
Summary
  'master/stage3/bin/zig build-exe /home/andy/dev/groovebasin/src/server/server_main.zig ...
    1.11 ± 0.03 times faster than 'intern-pool-3/stage3/bin/zig build-exe ...'

@andrewrk andrewrk merged commit 529ef75 into master Jun 13, 2023
@andrewrk andrewrk deleted the intern-pool-3 branch June 13, 2023 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants