performance_bottleneck
Identify and analyze performance bottlenecks in code using deep execution modeling. Input code path and suspected issues to pinpoint inefficiencies and optimize system performance.
Instructions
Use Gemini for deep performance analysis with execution modeling
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code_path | Yes | ||
| profile_depth | No |
Implementation Reference
- src/index.ts:621-649 (handler)MCP tool handler for 'performance_bottleneck': parses input schema, validates file paths, invokes DeepCodeReasonerV2.analyzePerformance, formats and returns result as MCP content.case 'performance_bottleneck': { const parsed = PerformanceBottleneckSchema.parse(args); // Validate the entry point file path const validatedPath = InputValidator.validateFilePaths([parsed.code_path.entry_point.file])[0]; if (!validatedPath) { throw new McpError( ErrorCode.InvalidParams, 'Invalid entry point file path', ); } const result = await deepReasoner.analyzePerformance( { ...parsed.code_path.entry_point, file: validatedPath }, parsed.profile_depth, parsed.code_path.suspected_issues ? InputValidator.validateStringArray(parsed.code_path.suspected_issues) : undefined, ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:85-95 (schema)Zod schema defining input validation for performance_bottleneck tool: code_path with entry_point and optional suspected_issues, plus profile_depth.const PerformanceBottleneckSchema = z.object({ code_path: z.object({ entry_point: z.object({ file: z.string(), line: z.number(), function_name: z.string().optional(), }), suspected_issues: z.array(z.string()).optional(), }), profile_depth: z.number().min(1).max(5).default(3), });
- src/index.ts:277-303 (registration)Tool registration in MCP listTools handler: defines name, description, and JSON schema matching the Zod schema for input validation.{ name: 'performance_bottleneck', description: 'Use Gemini for deep performance analysis with execution modeling', inputSchema: { type: 'object', properties: { code_path: { type: 'object', properties: { entry_point: { type: 'object', properties: { file: { type: 'string' }, line: { type: 'number' }, function_name: { type: 'string' }, }, required: ['file', 'line'], }, suspected_issues: { type: 'array', items: { type: 'string' } }, }, required: ['entry_point'], }, profile_depth: { type: 'number', minimum: 1, maximum: 5, default: 3 }, }, required: ['code_path'], }, },
- Core performance analysis helper invoked by tool handler: gathers relevant code files using performance patterns, delegates to GeminiService.performPerformanceAnalysis.async analyzePerformance( entryPoint: CodeLocation, profileDepth: number = 3, suspectedIssues?: string[], ): Promise<{ analysis: string; filesAnalyzed: string[]; }> { const codeFiles = new Map<string, string>(); // Read entry point and related files codeFiles.set(entryPoint.file, await this.codeReader.readFile(entryPoint.file)); // Find files that might affect performance const performancePatterns = ['Service', 'Repository', 'Query', 'Cache', 'Database']; const relatedFiles = await this.codeReader.findRelatedFiles(entryPoint.file, performancePatterns); // Read up to profileDepth related files for (let i = 0; i < Math.min(relatedFiles.length, profileDepth * 3); i++) { try { const content = await this.codeReader.readFile(relatedFiles[i]); codeFiles.set(relatedFiles[i], content); } catch (error) { // Skip unreadable files } } // Use Gemini for performance analysis const analysis = await this.geminiService.performPerformanceAnalysis( codeFiles, suspectedIssues || [], ); return { analysis, filesAnalyzed: Array.from(codeFiles.keys()), }; }