Skip to content

[bug] scip.scip.Index.deserializeBinary() fails to deserialize ~2 GiB index.scip file #407

Open
@mjames-c

Description

@mjames-c

To reproduce run the following TS script and see that it hangs after Deserializing index...

// NODE_OPTIONS='--max-old-space-size=40960' pnpm ts-node main.ts

import { createReadStream } from 'fs';
import * as scip from '@sourcegraph/scip-typescript/dist/src/scip';

async function readLargeFile(filePath: string): Promise<Buffer> {
    return new Promise((resolve, reject) => {
        const chunks: Buffer[] = [];
        const stream = createReadStream(filePath);
        
        stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
        stream.on('error', (error) => reject(error));
        stream.on('end', () => resolve(Buffer.concat(chunks)));
    });
}

async function main() {
    try {
        // Read the binary SCIP file using streams
        console.log('Reading SCIP file...');
        const buffer = await readLargeFile('index.scip');
        console.log('File read complete. Size:', buffer.length, 'bytes');
        
        // Deserialize the SCIP index
        console.log('Deserializing index...');
        const index = scip.scip.Index.deserializeBinary(buffer);
        
        // Log some basic information about the index
        console.log('\nSCIP Index Information:');
        const metadata = index.getMetadata();
        if (metadata) {
            console.log('Project Root:', metadata.getProjectRoot());
            const toolInfo = metadata.getToolInfo();
            if (toolInfo) {
                console.log('Tool Name:', toolInfo.getName());
                console.log('Tool Version:', toolInfo.getVersion());
            }
        }
        
        const documents = index.getDocumentsList();
        console.log('\nDocuments:', documents.length);
        
        // Show information about the first few documents
        documents.slice(0, 5).forEach((doc, i) => {
            console.log(`\nDocument ${i + 1}:`);
            console.log('Path:', doc.getRelativePath());
            console.log('Language:', scip.scip.Language[doc.getLanguage()]);
            console.log('Occurrences:', doc.getOccurrencesList().length);
            console.log('Symbols:', doc.getSymbolsList().length);
        });
        
    } catch (error) {
        console.error('Error processing SCIP file:', error);
    }
}

main();

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions