Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/core/domain_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func NewDomainExtractor(ctx context.Context, config *DomainExtractorConfig) (*Do
cancel: cancel,
stringPool: sync.Pool{
New: func() interface{} {
return strings.Builder{}
return &strings.Builder{}
},
},
// outputMap (sync.Map) is ready for use as its zero value is a valid, empty map.
Expand Down Expand Up @@ -421,11 +421,14 @@ func (de *DomainExtractor) processSingleLogForDomains(ctlog *certlib.CTLogInfo)
// This ensures thread-safe access and proper resource management during shutdown.
lw := &lockedWriter{
writer: writer,
gzWriter: gzWriter, // Will be nil if not compressing.
file: file,
filePath: tempFilePath,
finalPath: filePath,
}
// Only set gzWriter if compression is enabled to avoid nil interface issues
if de.config.CompressOutput && gzWriter != nil {
lw.gzWriter = gzWriter
}
de.outputMap.Store(ctlog.URL, lw)

// 3. Calculate and Submit Work Blocks.
Expand Down Expand Up @@ -629,7 +632,7 @@ func (de *DomainExtractor) domainExtractorCallback(item *WorkItem) error {
// Use a strings.Builder from a sync.Pool to efficiently build the batch of CSV lines.
// This significantly reduces string concatenation overhead and allocations.
sbInterface := de.stringPool.Get()
sb := sbInterface.(strings.Builder) // Type assertion.
sb := sbInterface.(*strings.Builder) // Type assertion.
sb.Reset() // Ensure builder is clean.
// Pre-allocate a reasonable buffer size for the string builder.
// Average line length can vary, estimate ~200-500 bytes per CSV line.
Expand Down
9 changes: 6 additions & 3 deletions internal/core/download_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func NewDownloadManager(ctx context.Context, config *DownloadConfig) (*DownloadM
cancel: cancel,
stringPool: sync.Pool{
New: func() interface{} {
return strings.Builder{}
return &strings.Builder{}
},
},
}
Expand Down Expand Up @@ -398,11 +398,14 @@ func (dm *DownloadManager) processSingleLogForDownload(ctlog *certlib.CTLogInfo)
// Store the locked writer instance
lw := &lockedWriter{
writer: writer,
gzWriter: gzWriter,
file: file,
filePath: tempFilePath,
finalPath: filePath,
}
// Only set gzWriter if compression is enabled to avoid nil interface issues
if dm.config.CompressOutput && gzWriter != nil {
lw.gzWriter = gzWriter
}
dm.outputMap.Store(ctlog.URL, lw)

// Submit Work Blocks in chunks for more even distribution
Expand Down Expand Up @@ -611,7 +614,7 @@ func (dm *DownloadManager) downloadCallback(item *WorkItem) error {

// Reset and return the builder to the pool
sb.Reset()
dm.stringPool.Put(&sb)
dm.stringPool.Put(sb)

// Lock once for the entire write
lw.mu.Lock()
Expand Down
Loading