You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Performance] O(n) linear search in getColumn() causes bottleneck in batch writes #138
When performing batch writes using TableEditor, the getColumn() method is called frequently. However, the current implementation uses a linear foreach loop to search for the column by name, resulting in an O(n) time complexity per call. This causes a significant performance bottleneck when dealing with large datasets.
Every call iterates through the entire $this->header->columns array.
Suggested Solution
To optimize this, I suggest building an associative map (hash map) when the header is initialized or columns are added. This would reduce the lookup time complexity to O(1).
for example:
// When building/initializing the headerprotected array $columnMap = [];
publicfunctionaddColumn(Column$column): void
{
$this->header->columns[] = $column;
$this->columnMap[strtolower($column->name)] = $column;
}
publicfunctiongetColumn(string$name): Column
{
$name = strtolower($name);
if (!isset($this->columnMap[$name])) {
thrownew \Exception("Column $name not found");
}
return$this->columnMap[$name];
}
Activity