Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Optimization regarding memory allocation #308

Copy link
Copy link
@Rungee

Description

@Rungee
Issue body actions

Hi,

I was profiling my GIS application and trying to find potential places in the current implementation where some optimizations could be made. Mostly I tested the performance of fetching the data in bytea format. As a result, I found out that memory allocation is not efficient in some cases.
More precisely, the memory is allocated every time we read data for each column in the NpgsqlAsciiRow class.

           byte[] buffer = new byte[fieldSize]; 
           PGUtil.CheckedStreamRead(Stream, buffer, 0, fieldSize);

In the case of bytea conversion, the byte array buffer is then used to create another one in the function ByteaTextToByteArray.

            // PostgreSQL 8.5+'s bytea_output=hex format
            byte[] result = new byte[(byteALength - 2) / 2];

Therefore, in theory we could reuse buffer several times, namely we could somehow store the byte[] buffer in memory and resize it if the size of a new field is greater the previous one. However, this new approach requires additional variable that defines actual length of data in the buffer.
Second, we could also think about reusing the byte[] which is returned by ByteaTextToByteArray. For instance, in a GIS application one only needs to read data from an array of bytes then convert this byte array to a Geometry object. Next, the array of bytes is no longer needed and can be returned to Npgsql to be reused.

I believe that the raised points should be discussed further as the memory allocation directly influences the performance of any program which uses Npgsql.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.