Performance Issues
Diagnosis
Slow Extraction
Recursive Extraction
Solutions
Limit recursion depth
# Extract only what you need with filter
Excavate::Archive.new('installer.msi').extract(
recursive_packages: true,
filter: '**/*.dll' # Reduces work
)Skip nested if not needed
# Only use recursive when needed
Excavate::Archive.new('archive.zip').extract # No recursiveMemory Issues
High Memory Usage
Solutions
Process files one at a time
# Good: Process and release
archive.files do |path|
process_file(path)
# Memory released after each file
end
# Bad: Load all into memory
all_content = archive.files do |path|
File.read(path) # Accumulates
endUse streaming
# Read files in chunks
archive.files do |path|
File.open(path, 'rb') do |f|
while chunk = f.read(8192)
process_chunk(chunk)
end
end
endDisk Space Issues
Insufficient Space
Solution
Check space before extraction:
def sufficient_space?(path, required_mb)
stat = if File.directory?(path)
`df -m #{path}`.split("\n").last.split[3].to_i
else
`df -m #{File.dirname(path)}`.split("\n").last.split[3].to_i
end
stat >= required_mb
end
unless sufficient_space?(target, 1000)
raise "Insufficient disk space"
endBatch Processing Issues
Slow Batch Processing
Solutions
Parallel processing
require 'parallel'
Parallel.each(archives, in_threads: 4) do |archive|
Excavate::Archive.new(archive).extract
endSequential with progress
archives.each_with_index do |archive, i|
puts "[#{i + 1}/#{archives.size}] Processing..."
Excavate::Archive.new(archive).extract
endPerformance Checklist
-
Use filters to extract only needed files
-
Extract to fast local storage
-
Process files one at a time with
filesmethod -
Avoid loading entire files into memory
-
Use parallel processing for independent archives
-
Check disk space before extraction