Performance: Loading CSV and Excel files
MEDIUM IMPACT
This affects the initial data loading time and memory usage, impacting how fast the app can start processing and responding.
import pandas as pd def load_file_good(file_path): # Load file in chunks or use streaming when possible if file_path.endswith('.csv'): chunks = pd.read_csv(file_path, chunksize=10000) data = pd.concat(chunks) else: # For Excel, load only needed sheets or rows data = pd.read_excel(file_path, nrows=10000) return data
import pandas as pd def load_file_bad(file_path): # Load entire file into memory at once if file_path.endswith('.csv'): data = pd.read_csv(file_path) else: data = pd.read_excel(file_path) return data
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous full file load | Minimal DOM changes | 0 | Low paint cost but delayed | [X] Bad |
| Chunked or partial file load | Minimal DOM changes | 0 | Low paint cost and timely | [OK] Good |