+
Skip to content

fix: reduce memory allocation on Column.label used for accessing in query #564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

AlexRiedler
Copy link
Contributor

Given the simple example as provided in the documentation provided (see https://www.ktorm.org/en/query.html)

val query = database.from(Employees).select()

query
    .map { row -> Emp(row[Employees.id], row[Employees.name], row[Employees.salary]) }

this will actually generate a label per row per column in order to access the element in the table via call stack of:

QueryRowSet.get(Column)
Column.getLabel()
Column.toString("_")

however, this getter initializes a string on every instance, so if you have 1000 rows, this will generate 1000 strings x the number of columns that are all the same for every call.

Alternative approaches

  • Initialize the string when initializing the Column itself (not using lazy)
  • Use lazy with a different synchronization mode

As always, thanks for reading and maintaining the library!

@vincentlauvlwj vincentlauvlwj changed the base branch from master to dev July 12, 2024 09:33
@vincentlauvlwj vincentlauvlwj merged commit 2e2ab58 into kotlin-orm:dev Jul 12, 2024
@vincentlauvlwj
Copy link
Member

Thanks for the PR!

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
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载