Skip to content

Commit 8fdbf45

Browse files
committed
perf: optimize defected DP memory with bit-packing and deferred reconstruction
- Replace separate Fd_type and Fd_param 4D arrays with a single uint16 Fd_packed array. - Use bit-packing to store both decision type (3 bits) and cut parameter (13 bits). - Defer reconstruction of cut sequences to the solve phase to reduce allocation overhead.
1 parent 3d46891 commit 8fdbf45

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/guillotine/core/dp_solver.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@
66
DECISION_FILL,
77
DECISION_CUT_X,
88
DECISION_CUT_Y,
9-
DECISION_DEFECT,
10-
DECISION_PURE,
119
)
1210

13-
# Bit layout for Fd_packed (uint16):
14-
# bits 15-13 : decision type (DECISION_* constants, values 0-5)
15-
# bits 12-0 : cut parameter (cut position z, max 8191)
16-
_PACK_SHIFT = 13
17-
_PACK_MASK = 0x1FFF
18-
1911

2012
class GuillotineDP:
2113
"""Optimized DP solver."""
@@ -175,10 +167,12 @@ def _reconstruct_F(self, w, h):
175167

176168
def _reconstruct_Fd(self, x, y, w, h):
177169
"""Finds the optimal cut by checking which candidate cut produces the target value."""
178-
if w <= 0 or h <= 0: return 'empty'
170+
if w <= 0 or h <= 0:
171+
return 'empty'
179172

180173
target_val = int(self.Fd_values[w, h, x, y])
181-
if target_val == 0: return 'empty'
174+
if target_val == 0:
175+
return 'empty'
182176

183177
# If pure, delegate to the 2D reconstruction (which still has types/params)
184178
if self.geom.prefix[x+w, y+h] - self.geom.prefix[x, y+h] - self.geom.prefix[x+w, y] + self.geom.prefix[x, y] == 0:

0 commit comments

Comments
 (0)