Skip to content

fix: fix string size calculation BED-7260#28

Merged
bsheth711 merged 1 commit intomainfrom
BED-7260-fix-string-size-calculation
Feb 5, 2026
Merged

fix: fix string size calculation BED-7260#28
bsheth711 merged 1 commit intomainfrom
BED-7260-fix-string-size-calculation

Conversation

@bsheth711
Copy link
Contributor

@bsheth711 bsheth711 commented Feb 5, 2026

Description

Describe your changes in detail

This PR fixes calculation of string size in memory. Currently the string header size is multiplied by the length of the string, leading to a significant overestimation in size. Instead, the string header size should be added to the length of the string as len(str) already returns the number of bytes in the string. See: https://pkg.go.dev/builtin#len

Motivation and Context

Why is this change required? What problem does it solve?

This fix resolves a bug discovered investigating BED-7260. Specifically, it was discovered that memory consumption was being overreported by DAWGs due to incorrectly calculating string size in memory, causing traversals to be cancelled.

How Has This Been Tested?

This has been tested locally with unit tests and observationally running graph queries.

Screenshots (optional):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

@bsheth711 bsheth711 requested a review from zinic February 5, 2026 19:40
@bsheth711 bsheth711 self-assigned this Feb 5, 2026
@bsheth711 bsheth711 added bug Something isn't working go Pull requests that update go code labels Feb 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

Walkthrough

These changes correct the memory size calculation for strings in the size utility package by switching from multiplication to addition, and update corresponding test expectations to reflect the revised calculations.

Changes

Cohort / File(s) Summary
Size calculation logic
util/size/size.go
Changed string size calculation from multiplication to addition (totalSize *= Size(len(typedValue))totalSize += Size(len(typedValue))), affecting how string inner allocations are accounted for in total size.
Direct size utility tests
util/size/size_test.go
Updated expected values in TestOfAny for string and slice types with detailed breakdown comments explaining header sizes and totals (0x40→0x14, 0x108→0x57, 0x44→0x36).
Graph properties tests
graph/properties_test.go
Adjusted SizeOf() test assertions to reflect updated calculations (440→146, 296→105, 256→78, 1600→478).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • zinic
  • ALCooper12

Poem

🐰 A calculation fixed with care,
From times to plus, a change so fair,
String sizes now reported true,
Tests updated, all made new,
Size allocation's mystery solved! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change in the pull request, which is fixing a bug in string size calculation as documented in the PR objectives.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BED-7260-fix-string-size-calculation

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@zinic zinic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@bsheth711 bsheth711 merged commit 794550d into main Feb 5, 2026
2 checks passed
@bsheth711 bsheth711 deleted the BED-7260-fix-string-size-calculation branch February 5, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants