Skip to content
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

grn_io: don't use division in grn_io_win_map() #440

Closed
s-yata opened this issue Dec 1, 2015 · 3 comments
Closed

grn_io: don't use division in grn_io_win_map() #440

s-yata opened this issue Dec 1, 2015 · 3 comments
Assignees
Labels

Comments

@s-yata
Copy link
Contributor

s-yata commented Dec 1, 2015

Description

In some cases, grn_io_win_map() is called many times and the cost of an integer division may affect the performance.

  • groonga/lib/io.c

    Lines 989 to 993 in 9c8a355

    if (offset >= segment_size) {
    segment += offset / segment_size;
    offset = offset % segment_size;
    }
    nseg = (offset + size + segment_size - 1) / segment_size;
  if (offset >= segment_size) {
    segment += offset / segment_size;
    offset = offset % segment_size;
  }
  nseg = (offset + size + segment_size - 1) / segment_size;

Hint

segment_size is generally a power of two and divisions can be replaced with a bitwise-shift or bitwise-and.

@s-yata s-yata self-assigned this Dec 1, 2015
@s-yata
Copy link
Contributor Author

s-yata commented Dec 1, 2015

I've compared a division based implementation and a bitwise-shift based implementation, but I could not find significant differences.

@s-yata
Copy link
Contributor Author

s-yata commented Dec 1, 2015

The attached files are the patches I tested.

@s-yata
Copy link
Contributor Author

s-yata commented Dec 1, 2015

Rejected!

@s-yata s-yata added the done label Dec 1, 2015
@s-yata s-yata closed this as completed Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant