authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-04 18:48:08-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-04 18:48:08-07:00
log9e81222d9281f8d26e32578fe3cef54e0c7d5232
treea815f901a46916c8b3b1e5c833395229159e44b9
parent88acdb9aa6cdb8ea20e02c4d0f85be81f696897c

zig reduce: some adjustments to make it go faster

* don't reset the rng. it seems like it was getting stuck trying the same transforms over and over again. * slide the window over after failing a large transform set, idea being that transformations in the failed set are more likely to be problematic.

1 files changed, 9 insertions(+), 4 deletions(-)

src/reduce.zig+9-4
...@@ -166,7 +166,10 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -166,7 +166,10 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
166 var start_index: usize = 0;166 var start_index: usize = 0;
167167
168 while (start_index < transformations.items.len) {168 while (start_index < transformations.items.len) {
169 subset_size = @max(1, subset_size / 2);169 const prev_subset_size = subset_size;
170 subset_size = @max(1, subset_size * 3 / 4);
171 if (prev_subset_size > 1 and subset_size == 1)
172 start_index = 0;
170173
171 const this_set = transformations.items[start_index..][0..subset_size];174 const this_set = transformations.items[start_index..][0..subset_size];
172 std.debug.print("trying {d} random transformations: ", .{subset_size});175 std.debug.print("trying {d} random transformations: ", .{subset_size});
...@@ -237,9 +240,6 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -237,9 +240,6 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
237 tree = new_tree;240 tree = new_tree;
238241
239 try Walk.findTransformations(arena, &tree, &transformations);242 try Walk.findTransformations(arena, &tree, &transformations);
240 // Resetting based on the seed again means we will get the same
241 // results if restarting the reduction process from this new point.
242 rng = std.rand.DefaultPrng.init(seed);
243 sortTransformations(transformations.items, rng.random());243 sortTransformations(transformations.items, rng.random());
244244
245 continue :fresh;245 continue :fresh;
...@@ -249,6 +249,11 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -249,6 +249,11 @@ pub fn main(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
249 // If we tested only one transformation, move on to the next one.249 // If we tested only one transformation, move on to the next one.
250 if (subset_size == 1) {250 if (subset_size == 1) {
251 start_index += 1;251 start_index += 1;
252 } else {
253 start_index += subset_size;
254 if (start_index + subset_size > transformations.items.len) {
255 start_index = 0;
256 }
252 }257 }
253 },258 },
254 }259 }