Skip to content

feat: Removed Column Index lookup - #2593

Open
bbernays wants to merge 2 commits into
mainfrom
set-resource-with-index
Open

feat: Removed Column Index lookup#2593
bbernays wants to merge 2 commits into
mainfrom
set-resource-with-index

Conversation

@bbernays

@bbernays bbernays commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Simplified implementation of #2592 that handles the main call site. In the future we can look at implementing a more fully implemented cache

@erezrokah

Copy link
Copy Markdown
Member

My suggestion in #2592 was wrong. TransformWithStruct defaults every column to schema.PathResolver, which calls r.Set(c.Name, ...), so the Resolver == nil branch here is almost never taken and the linear lookup stays.

To cover it, make Set itself fast: store the current column index on the resource before calling the resolver, and have Set check it first.

// schema/resource.go
type Resource struct {
    // ...
    columnIndexHint int
}

func (r *Resource) Set(columnName string, value any) error {
    index := r.columnIndexHint
    if index < 0 || index >= len(r.data) || r.Table.Columns[index].Name != columnName {
        index = r.Table.Columns.Index(columnName)
        if index == -1 {
            panic(columnName + " column not found")
        }
    }
    // existing r.data[index].Set(value) + panic on error
}

func (r *Resource) setColumnIndexHint(i int) { r.columnIndexHint = i }

resolveColumn calls resource.setColumnIndexHint(colIndex) before column.Resolver(...) or Set. Since scheduler/resolvers is a separate package, the setter must be exported (or the loop moves into schema). This removes the need for SetWithIndex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants