Skip to content

perf(graph): use strings.IndexByte instead of strings.Contains for single char - #694

Merged
saad-h1 merged 3 commits into
mainfrom
perf/wg-index-byte
Oct 15, 2026
Merged

saad-h1 merged 3 commits into
mainfrom
perf/wg-index-byte

Conversation

@saad-h1

@saad-h1 saad-h1 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Small performance improvement in weighted graph that @senojj noticed we can make, to use strings.IndexByte instead of strings.Contains when checking for a single char.

Benchmark:

goos: darwin
goarch: arm64
pkg: github.com/openfga/language/pkg/go/graph
cpu: Apple M4 Max
BenchmarkContains-16            491992227                2.349 ns/op
BenchmarkIndexByte-16           634691439                1.816 ns/op
PASS
ok      github.com/openfga/language/pkg/go/graph        3.098s

Copilot AI balanced review requested due to automatic review settings October 9, 2026 15:32
@saad-h1
saad-h1 requested a review from a team as a code owner October 9, 2026 15:32
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: db2ff9c9-b7f1-4d6e-9cf0-94b82956037e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d82dafde-b202-4a5b-ac44-c53e42385094
📥 Commits

Reviewing files that changed from the base of the PR and between f558baa and a44dc54.

📒 Files selected for processing (1)
  • pkg/go/graph/weighted_graph.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

GetNodeWeight and GetEdgeWeight now use strings.IndexByte to detect # in keys. Their existing routing behavior remains unchanged.

Changes

Weighted graph key routing

Layer / File(s) Summary
Detect userset keys
pkg/go/graph/weighted_graph.go
GetNodeWeight and GetEdgeWeight use strings.IndexByte instead of strings.Contains to check for #. Their routing behavior is unchanged.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Refactor

Suggested reviewers: yissellokta

Merge Risk: ⚪ Minimal · up to a44dc

This is a localized search optimization with no established behavior change or actionable merge-blocking risk.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: replacing strings.Contains with strings.IndexByte for a single-character check as a performance optimization.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The replacements are behaviorally equivalent, localized, and covered by existing userset tests.

0 open findings

What changed in this PR

Optimizes single-character checks in the weighted graph without changing behavior.

Changes:

  • Replaces strings.Contains with faster strings.IndexByte checks.
File Description
pkg/​go/​graph/​weighted_graph.go Optimizes # detection for node and edge weight lookups.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@yissellokta

Copy link
Copy Markdown
Contributor

@saad-h1 lint is failing

@saad-h1

saad-h1 commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

"lint" is failing due to vulns, resolving in #699

also going to separate lint and vulns in CI in #697

@saad-h1
saad-h1 added this pull request to the merge queue Oct 15, 2026
Merged via the queue into main with commit 2aed764 Oct 15, 2026
16 checks passed
@saad-h1
saad-h1 deleted the perf/wg-index-byte branch October 15, 2026 17:25
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.

6 participants