Skip to content

Add parallel batch evaluation API#26

Closed
Copilot wants to merge 4 commits intomasterfrom
copilot/support-parallel-evaluation
Closed

Add parallel batch evaluation API#26
Copilot wants to merge 4 commits intomasterfrom
copilot/support-parallel-evaluation

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 13, 2026

Casbin's BatchEnforce API needs efficient parallel evaluation of the same expression against many parameter sets. The existing Eval method is thread-safe but lacks a convenient batch API.

Changes

  • New batch evaluation methods

    • EvaluateBatch() - sequential evaluation across parameter sets
    • EvaluateBatchParallel() - parallel evaluation with configurable worker count
    • EvaluationResult struct encapsulating result and error per parameter set
  • Comprehensive test coverage

    • Concurrent safety validation (race detector)
    • Batch evaluation with varying worker configurations
    • Error handling in batch operations
    • Casbin-style access control example
  • Performance benchmarks

    • Sequential vs parallel batch evaluation
    • Worker count tuning (1, 4, 10, unlimited)

Usage

expression, _ := govaluate.NewEvaluableExpression("(requests_made * requests_succeeded / 100) >= 90")

parameterSets := []map[string]interface{}{
    {"requests_made": 100, "requests_succeeded": 95},
    {"requests_made": 100, "requests_succeeded": 85},
}

// Parallel evaluation with 4 workers
results := expression.EvaluateBatchParallel(parameterSets, 4)

for i, result := range results {
    if result.Error == nil {
        fmt.Printf("Result %d: %v\n", i, result.Result)
    }
}

The parallel version provides better throughput on multi-core systems for large batch sizes. Pass maxWorkers=0 for fully parallel execution or specify a limit to control resource usage.

Original prompt

This section details on the original issue you should resolve

<issue_title>[feature] support parallel evaluation with good performance</issue_title>
<issue_description>This requirement originates from Casbin's BatchEnforce API: apache/casbin#710

But it can benefit all other projects which want to use this feature</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@nomeguy nomeguy marked this pull request as ready for review January 13, 2026 17:44
Copilot AI and others added 3 commits January 13, 2026 17:47
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for parallel evaluation with good performance Add parallel batch evaluation API Jan 13, 2026
Copilot AI requested a review from nomeguy January 13, 2026 17:54
@nomeguy nomeguy closed this Jan 13, 2026
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.

[feature] support parallel evaluation with good performance

3 participants