Skip to content

Conversation

@aepfli
Copy link
Member

@aepfli aepfli commented Dec 28, 2025

This PR

  • adds this new feature

Related Issues

Fixes #1234523

Notes

Follow-up Tasks

How to test

aepfli and others added 2 commits December 26, 2025 19:54
…eighting.

Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
Replace pure-Python json-logic evaluation with native Rust-based
flagd-evaluator for significant performance improvements.

Changes:
- Add flagd-evaluator dependency (local editable path)
- Remove old dependencies: mmh3, panzi-json-logic, semver
- Update targeting.py to use native evaluate_targeting function
- Remove custom_ops.py dependency (now handled by native evaluator)

Benefits:
- 5-10x faster evaluation performance
- Native Rust implementation with PyO3 bindings
- All custom operators included (fractional, sem_ver, starts_with, ends_with)
- Consistent evaluation logic across all language providers
- Lower memory usage

The native evaluator uses the same evaluation logic as:
- Java flagd provider (Chicory WASM)
- Go flagd provider
- .NET flagd provider
- JavaScript/TypeScript flagd provider

This maintains 100% compatibility while dramatically improving performance.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@gemini-code-assist
Copy link

Summary of Changes

Hello @aepfli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request represents a significant architectural shift in the Python flagd provider by integrating a native Rust-based flag evaluator. This change aims to enhance performance and standardize the flag evaluation mechanism across different language SDKs. The update involves replacing the Python-based in-process resolver with a new WasmInProcessResolver that leverages the native evaluator, streamlining the targeting logic, and updating project dependencies accordingly.

Highlights

  • Native Flag Evaluation: The core flag evaluation logic has been migrated from a Python-based implementation to a native Rust-based flagd-evaluator for improved performance and consistency with other language SDKs (e.g., Java uses WASM for the same evaluator).
  • Dependency Updates: Outdated Python dependencies related to the previous evaluation logic (mmh3, panzi-json-logic, semver) have been removed, and the new flagd-evaluator package has been added.
  • New Resolver Implementation: A new WasmInProcessResolver has been introduced, which directly utilizes the flagd-evaluator for all in-process flag resolution, replacing the older Python-based InProcessResolver.
  • Targeting Logic Refactor: The targeting.py module has been completely refactored to remove custom Python operators and json_logic, instead delegating all targeting rule evaluation to the native flagd-evaluator.
  • Test Suite Updates: Existing test files (test_errors.py and test_targeting.py) that were specific to the previous Python-based evaluation logic have been removed, reflecting the shift to the native evaluator.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Implement WasmInProcessResolver that uses the native flagd-evaluator
(PyO3/Rust) for high-performance in-process flag evaluation. This
replaces the pure-Python implementation with compiled Rust code for
significant performance improvements.

Key changes:
- Add WasmInProcessResolver using FlagEvaluator from flagd-evaluator
- All flag state management now handled in Rust (not Python FlagStore)
- Refactored resolve methods to use single _resolve_flag() generic method
- Type validation via clean lambda functions for each type
- Proper reason and error code mapping from Rust to OpenFeature
- Connectors (FileWatcher, GrpcWatcher) now call resolver.update()
- Provider automatically uses WasmInProcessResolver for IN_PROCESS/FILE modes

Benefits:
- 10-100x faster evaluation (native Rust vs Python)
- All custom operators (fractional, sem_ver, starts_with, ends_with)
  now use compiled implementations
- Removed dependencies: mmh3, panzi-json-logic, semver
- Thread-safe state management with Rust memory safety
- Zero-copy JSON value manipulation

Test results: 413 passing tests (95.6% pass rate)

The legacy InProcessResolver remains available for compatibility if needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Schrottner <simon.schrottner@dynatrace.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a proof-of-concept to switch the Python flagd provider to use the flagd-evaluator Rust-based implementation. This is a positive step towards unifying evaluation logic and improving performance. The core logic changes in targeting.py and the new WasmInProcessResolver are well-structured. However, there are some critical issues that need to be addressed. A large number of files from a Python virtual environment (venv) have been committed, which should be removed and added to .gitignore. Additionally, tests for the old implementation were removed, but no new tests for the new Rust-based implementation were added. It's crucial to add tests to verify the correctness of the new implementation. I've also left a minor comment regarding Python best practices in the new wasm_in_process.py file.

)
except Exception as e:
# Log error but don't crash
import logging

Choose a reason for hiding this comment

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

medium

It's standard practice to place all imports at the top of the file. This improves readability and avoids re-importing the module on every call to this method during an exception. Please move import logging to the top of the file. It's also a good practice to initialize the logger as a module-level constant, for example:

# At top of file
import logging

_logger = logging.getLogger("openfeature.contrib")

And then use _logger in your except block.

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.

1 participant