|
| 1 | +# Assembly Import Process Optimization Plan |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document outlines the plan for optimizing the assembly import process in dbatools.library while maintaining critical platform-specific functionality, particularly for SqlClient. |
| 6 | + |
| 7 | +## Current State Analysis |
| 8 | + |
| 9 | +```mermaid |
| 10 | +graph TD |
| 11 | + A[Assembly Import Process] --> B[Assembly Lists] |
| 12 | + A --> C[Platform Resolution] |
| 13 | + A --> D[Assembly Loading] |
| 14 | + B --> E[Multiple Lists] |
| 15 | + B --> F[Duplicate Entries] |
| 16 | + C --> G[Generic Resolution] |
| 17 | + C --> H[SqlClient Specific] |
| 18 | + D --> I[Multiple Loading Methods] |
| 19 | + D --> J[Redundant Error Handling] |
| 20 | +``` |
| 21 | + |
| 22 | +### Identified Issues |
| 23 | + |
| 24 | +1. Assembly Lists |
| 25 | + - Redundant entries between CoreAssemblies and CommonAssemblies |
| 26 | + - Duplicate assembly references in load order |
| 27 | + - Separate lists for similar purposes |
| 28 | + |
| 29 | +2. Path Resolution |
| 30 | + - Similar logic in both redirector and resolver |
| 31 | + - Multiple checks for same paths |
| 32 | + - Some redundant platform detection |
| 33 | + |
| 34 | +3. Assembly Loading |
| 35 | + - Multiple loading mechanisms that could conflict |
| 36 | + - Redundant loading attempts |
| 37 | + - Inconsistent error handling |
| 38 | + |
| 39 | +## Implementation Plan |
| 40 | + |
| 41 | +### 1. SqlClient-Specific Handling (Priority: High) |
| 42 | + |
| 43 | +Preserve and optimize platform-specific handling for SqlClient: |
| 44 | + |
| 45 | +```mermaid |
| 46 | +graph TD |
| 47 | + A[SqlClient Handling] --> B[Platform Detection] |
| 48 | + A --> C[SNI Loading] |
| 49 | + A --> D[Path Resolution] |
| 50 | + B --> E[Windows Specific] |
| 51 | + B --> F[Unix Specific] |
| 52 | + C --> G[Architecture Check] |
| 53 | + C --> H[Native Loading] |
| 54 | + D --> I[Platform Paths] |
| 55 | + D --> J[Version Check] |
| 56 | +``` |
| 57 | + |
| 58 | +Key Changes: |
| 59 | +- Maintain dedicated platform resolution |
| 60 | +- Keep architecture-specific SNI loading |
| 61 | +- Preserve Windows vs Unix distinctions |
| 62 | +- Document platform requirements |
| 63 | + |
| 64 | +Files to Modify: |
| 65 | +- assembly-loader.ps1: SNI loading logic |
| 66 | +- assembly-resolution.ps1: Platform detection |
| 67 | +- assembly-redirector.ps1: SqlClient handling |
| 68 | + |
| 69 | +### 2. Assembly List Optimization (Priority: Medium) |
| 70 | + |
| 71 | +Optimize assembly lists while maintaining platform-specific requirements: |
| 72 | + |
| 73 | +```mermaid |
| 74 | +graph TD |
| 75 | + A[Assembly Lists] --> B[Core Lists] |
| 76 | + A --> C[Platform Lists] |
| 77 | + B --> D[Remove Duplicates] |
| 78 | + B --> E[Optimize Order] |
| 79 | + C --> F[Windows Specific] |
| 80 | + C --> G[Unix Specific] |
| 81 | + C --> H[DAC Specific] |
| 82 | +``` |
| 83 | + |
| 84 | +Key Changes: |
| 85 | +- Remove truly redundant entries |
| 86 | +- Maintain platform-specific lists |
| 87 | +- Keep DAC assemblies separate |
| 88 | +- Optimize load order |
| 89 | + |
| 90 | +Files to Modify: |
| 91 | +- assembly-lists.ps1: List definitions |
| 92 | +- assembly-loader.ps1: Load order implementation |
| 93 | + |
| 94 | +### 3. Path Resolution Refinement (Priority: Medium) |
| 95 | + |
| 96 | +Improve path resolution while maintaining platform checks: |
| 97 | + |
| 98 | +```mermaid |
| 99 | +graph TD |
| 100 | + A[Path Resolution] --> B[Generic Resolution] |
| 101 | + A --> C[SqlClient Resolution] |
| 102 | + B --> D[Cache Paths] |
| 103 | + B --> E[Basic Checks] |
| 104 | + C --> F[Platform Checks] |
| 105 | + C --> G[Native Paths] |
| 106 | +``` |
| 107 | + |
| 108 | +Key Changes: |
| 109 | +- Separate generic and SqlClient resolution |
| 110 | +- Implement path caching |
| 111 | +- Maintain platform-specific paths |
| 112 | +- Simplify non-critical checks |
| 113 | + |
| 114 | +Files to Modify: |
| 115 | +- assembly-resolution.ps1: Path resolution logic |
| 116 | +- assembly-redirector.ps1: Platform-specific paths |
| 117 | + |
| 118 | +### 4. Loading Process Improvement (Priority: Medium) |
| 119 | + |
| 120 | +Streamline loading while preserving platform requirements: |
| 121 | + |
| 122 | +```mermaid |
| 123 | +graph TD |
| 124 | + A[Assembly Loading] --> B[SqlClient Loading] |
| 125 | + A --> C[Generic Loading] |
| 126 | + B --> D[Platform Specific] |
| 127 | + B --> E[Version Check] |
| 128 | + C --> F[Consolidated Logic] |
| 129 | + C --> G[Error Handling] |
| 130 | +``` |
| 131 | + |
| 132 | +Key Changes: |
| 133 | +- Keep platform-specific SqlClient loading |
| 134 | +- Consolidate generic assembly loading |
| 135 | +- Improve error handling |
| 136 | +- Remove redundant checks |
| 137 | + |
| 138 | +Files to Modify: |
| 139 | +- assembly-loader.ps1: Loading logic |
| 140 | +- assembly-troubleshoot.ps1: Error handling |
| 141 | + |
| 142 | +## Implementation Order |
| 143 | + |
| 144 | +1. SqlClient-Specific Handling |
| 145 | + - Preserve critical platform functionality |
| 146 | + - Document requirements |
| 147 | + - Update SNI loading |
| 148 | + |
| 149 | +2. Assembly List Optimization |
| 150 | + - Remove redundant entries |
| 151 | + - Maintain platform lists |
| 152 | + - Update load order |
| 153 | + |
| 154 | +3. Path Resolution Refinement |
| 155 | + - Implement caching |
| 156 | + - Separate resolutions |
| 157 | + - Update platform checks |
| 158 | + |
| 159 | +4. Loading Process Improvement |
| 160 | + - Consolidate generic loading |
| 161 | + - Update error handling |
| 162 | + - Remove redundancy |
| 163 | + |
| 164 | +## Testing Recommendations |
| 165 | + |
| 166 | +1. Platform Testing |
| 167 | + - Test on Windows (x86, x64, ARM) |
| 168 | + - Test on Linux (x64, ARM) |
| 169 | + - Test on macOS (x64) |
| 170 | + |
| 171 | +2. Functionality Testing |
| 172 | + - SqlClient connectivity |
| 173 | + - DAC functionality |
| 174 | + - Assembly loading order |
| 175 | + - Error handling |
| 176 | + |
| 177 | +3. Performance Testing |
| 178 | + - Load time measurements |
| 179 | + - Memory usage tracking |
| 180 | + - Path resolution speed |
| 181 | + |
| 182 | +## Success Criteria |
| 183 | + |
| 184 | +1. All platform-specific functionality works correctly |
| 185 | +2. Reduced code duplication |
| 186 | +3. Improved error handling and logging |
| 187 | +4. Maintained backward compatibility |
| 188 | +5. No regression in functionality |
| 189 | + |
| 190 | +## Next Steps |
| 191 | + |
| 192 | +1. Review and approve plan |
| 193 | +2. Create backup of current implementation |
| 194 | +3. Begin with SqlClient-specific changes |
| 195 | +4. Proceed with remaining optimizations |
| 196 | +5. Comprehensive testing |
| 197 | +6. Documentation updates |
0 commit comments