Maker.WebServer: don't do linear search in the steps array #35458

Open
opened 2026-05-26 01:54:40 +02:00 by andrewrk · 0 comments
Owner

In Zig codebase, linear search is never OK. Mind your C.S. professor and fix your Big O's with a proper lookup table.

--- a/lib/compiler/Maker/WebServer.zig
+++ b/lib/compiler/Maker/WebServer.zig
@@ -225,7 +225,6 @@ pub fn updateStepStatus(
 ) void {
     const maker = ws.maker;
     const all_steps = maker.step_stack.keys();
-    // TODO don't do linear search, especially in a hot loop like this
     const step_idx: u32 = for (all_steps, 0..) |s, i| {
         if (s == step_index) break @intCast(i);
     } else unreachable;
@@ -799,7 +788,6 @@ pub fn updateTimeReportCompile(ws: *WebServer, opts: struct {
     const io = maker.graph.io;
     const all_steps = maker.step_stack.keys();
 
-    // TODO don't do linear search
     const step_idx: u32 = for (all_steps, 0..) |s, i| {
         if (s == opts.compile_step) break @intCast(i);
     } else unreachable;
@@ -843,7 +831,6 @@ pub fn updateTimeReportGeneric(ws: *WebServer, step_index: Configuration.Step.In
     const io = maker.graph.io;
     const all_steps = maker.step_stack.keys();
 
-    // TODO don't do linear search
     const step_idx: u32 = for (all_steps, 0..) |s, i| {
         if (s == step_index) break @intCast(i);
     } else unreachable;
@@ -882,7 +869,6 @@ pub fn updateTimeReportRunTest(
     const io = maker.graph.io;
     const all_steps = maker.step_stack.keys();
 
-    // TODO don't do linear search
     const step_idx: u32 = for (all_steps, 0..) |s, i| {
         if (s == run_step_index) break @intCast(i);
     } else unreachable;

part of todo eliminación (#363)

In Zig codebase, linear search is never OK. Mind your C.S. professor and fix your Big O's with a proper lookup table. ```diff --- a/lib/compiler/Maker/WebServer.zig +++ b/lib/compiler/Maker/WebServer.zig @@ -225,7 +225,6 @@ pub fn updateStepStatus( ) void { const maker = ws.maker; const all_steps = maker.step_stack.keys(); - // TODO don't do linear search, especially in a hot loop like this const step_idx: u32 = for (all_steps, 0..) |s, i| { if (s == step_index) break @intCast(i); } else unreachable; ``` ```diff @@ -799,7 +788,6 @@ pub fn updateTimeReportCompile(ws: *WebServer, opts: struct { const io = maker.graph.io; const all_steps = maker.step_stack.keys(); - // TODO don't do linear search const step_idx: u32 = for (all_steps, 0..) |s, i| { if (s == opts.compile_step) break @intCast(i); } else unreachable; @@ -843,7 +831,6 @@ pub fn updateTimeReportGeneric(ws: *WebServer, step_index: Configuration.Step.In const io = maker.graph.io; const all_steps = maker.step_stack.keys(); - // TODO don't do linear search const step_idx: u32 = for (all_steps, 0..) |s, i| { if (s == step_index) break @intCast(i); } else unreachable; @@ -882,7 +869,6 @@ pub fn updateTimeReportRunTest( const io = maker.graph.io; const all_steps = maker.step_stack.keys(); - // TODO don't do linear search const step_idx: u32 = for (all_steps, 0..) |s, i| { if (s == run_step_index) break @intCast(i); } else unreachable; ``` part of todo eliminación (#363)
andrewrk added this to the Upcoming milestone 2026-05-26 01:54:40 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ziglang/zig#35458
No description provided.