@@ -142,6 +142,43 @@ export function sortProcesses(
142142 const aValue = a [ sortConfig . field ] ;
143143 const bValue = b [ sortConfig . field ] ;
144144
145+ // Special handling for disk_usage which is an array [read_bytes, written_bytes]
146+ if ( sortConfig . field === "disk_usage" ) {
147+ const aRead = ( aValue as [ number , number ] ) [ 0 ] ;
148+ const aWrite = ( aValue as [ number , number ] ) [ 1 ] ;
149+ const bRead = ( bValue as [ number , number ] ) [ 0 ] ;
150+ const bWrite = ( bValue as [ number , number ] ) [ 1 ] ;
151+
152+ // Smart sorting: analyze if this is a read-heavy or write-heavy comparison
153+ const totalReads = aRead + bRead ;
154+ const totalWrites = aWrite + bWrite ;
155+
156+ if ( totalWrites > totalReads * 1.5 ) {
157+ // Write-heavy scenario: prioritize writes, use reads as tiebreaker
158+ if ( aWrite !== bWrite ) {
159+ return direction * ( aWrite - bWrite ) ;
160+ }
161+ return direction * ( aRead - bRead ) ;
162+ } else if ( totalReads > totalWrites * 1.5 ) {
163+ // Read-heavy scenario: prioritize reads, use writes as tiebreaker
164+ if ( aRead !== bRead ) {
165+ return direction * ( aRead - bRead ) ;
166+ }
167+ return direction * ( aWrite - bWrite ) ;
168+ } else {
169+ // Balanced I/O: sort by total, use max as tiebreaker
170+ const aTotalDisk = aRead + aWrite ;
171+ const bTotalDisk = bRead + bWrite ;
172+ if ( aTotalDisk !== bTotalDisk ) {
173+ return direction * ( aTotalDisk - bTotalDisk ) ;
174+ }
175+ // Tiebreaker: use the dominant operation
176+ const aMaxDisk = Math . max ( aRead , aWrite ) ;
177+ const bMaxDisk = Math . max ( bRead , bWrite ) ;
178+ return direction * ( aMaxDisk - bMaxDisk ) ;
179+ }
180+ }
181+
145182 // Type-specific comparisons
146183 if ( typeof aValue === "string" ) {
147184 return direction * aValue . localeCompare ( bValue as string ) ;
0 commit comments