Skip to content

docs(python): add GCI91 feasibility report and green metrics#459

Closed
harag7810 wants to merge 1 commit into
green-code-initiative:mainfrom
harag7810:feature/validate-gci91-python
Closed

docs(python): add GCI91 feasibility report and green metrics#459
harag7810 wants to merge 1 commit into
green-code-initiative:mainfrom
harag7810:feature/validate-gci91-python

Conversation

@harag7810

Copy link
Copy Markdown
Contributor

Context:
Rule GCI91 (Use filter feature before sort elements) was currently pending analysis for Python in the RULES.md file.
Our team (Les Buzz du decollage permanent) conducted a comprehensive benchmark using CodeCarbon to measure execution time, peak RAM allocation, and real hardware energy consumption (CPU and RAM) to validate if this rule delivers a concrete ecological value for the Python eco-design standard.

Test Protocol:
We compared sorting a complete dataset before filtering vs filtering the dataset first and sorting the remaining elements (keeping ~10% of the data).

  • Dataset 1 (Performance): 1,000,000 random integers.
  • Dataset 2 (Energy): 2,000,000 random integers.
    The tests were run over 10 sequential iterations with the Python Garbage Collector disabled to measure raw, unbiased hardware consumption.

Benchmark Results:

  1. Performance & Memory Metrics (1M items):
  • Non-Compliant Pattern (Sort then Filter): 1.7046 sec | Peak RAM: 11.41 Mo
  • Compliant Pattern (Filter then Sort): 0.3639 sec | Peak RAM: 1.87 Mo
  1. Hardware Energy & Carbon Metrics (2M items via CodeCarbon):
  • Non-Compliant Pattern (Sort then Filter):
    CPU Energy : 0.000000 kWh
    RAM Energy : 0.000009 kWh
    Emissions : 0.5258 mg CO2
  • Compliant Pattern (Filter then Sort):
    CPU Energy : 0.000000 kWh
    RAM Energy : 0.000002 kWh
    Emissions : 0.0979 mg CO2
  1. Optimization Ratios:
  • Execution Time Reduction: Divided by 4.68
  • Peak RAM Buffer Draw Optimization: Divided by 6.10
  • Total Carbon Footprint Reduction: Divided by 5.37
  • RAM Energy Draw Optimization: Divided by 4.50

Analysis & Conclusion:
The results perfectly validate the algorithmic theory. By filtering the dataset first, we dramatically reduce the 'n' parameter for Python's Timsort algorithm, which operates in O(n log n). This directly slashes CPU computation time and drastically lowers the peak RAM needed to hold the sorted array structures.
CodeCarbon metrics show a hardware energy footprint divided by more than 5, proving a massive ecological value.

Required Action:
A new feasibility report has been added to src/main/rules/GCI91/python/. We recommend updating the rule matrix state to applicable (active) for Python.

Comment thread src/main/rules/GCI91/python/GCI91.asciidoc

When the sorting node is identified as an input directly feeding a filter constraint, the rule engine can easily raise a violation issue recommending a structural inversion (filtering first, then sorting).

== 3. Benchmark and Technical Protocol

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @harag7810 could you give us more details on context of your local tests, and some image captures, the software used for example ?
could you write a documentation with the same template of the other rules ? ofr example, give us a non compliant code and a compliant code block.

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.

Pull request overview

Adds a Python-specific feasibility/benchmark report for rule GCI91 (“Use filter feature before sort elements”) to support moving the rule from “pending” toward “active/applicable” in the Python eco-design standard documentation set.

Changes:

  • Added an AsciiDoc feasibility and optimization report for GCI91 (Python) with benchmark protocol and results.
  • Documented performance, memory, and CodeCarbon-based energy/carbon measurements for “sort-then-filter” vs “filter-then-sort”.
  • Included an explicit recommendation to activate/apply the rule for Python based on observed deltas.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/rules/GCI91/python/GCI91.asciidoc
Comment thread src/main/rules/GCI91/python/GCI91.asciidoc
Comment thread src/main/rules/GCI91/python/GCI91.asciidoc
Comment thread src/main/rules/GCI91/python/GCI91.asciidoc
Comment thread src/main/rules/GCI91/python/GCI91.asciidoc
Comment on lines +62 to +63
== 6. Recommendation
Based on clear empirical evidence tracking hardware power consumption, implementing GCI91 delivers substantial infrastructure relief and carbon reduction without adding syntax complexity. We recommend shifting the rule state to applicable for Python.
@dedece35

dedece35 commented May 21, 2026

Copy link
Copy Markdown
Member

@harag7810 ,
please, update CHANGELOG.md and the icon of the rule in RULES.md

@dedece35

Copy link
Copy Markdown
Member

Hi @harag7810 ,
thank you for your work.

I was waiting for you to take into accounts review feebacks, but for lack of your answer, I decided to recteate a new PR from yours.
Here is the new one : #482

thus I close yours.

thank you again

@dedece35 dedece35 closed this Jul 10, 2026
@github-project-automation github-project-automation Bot moved this from Review in progress to Done in Hackathon Kanban - RULES-SPECIFICATIONS Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🗃️ rule rule improvment or rule development or bug 🔥 in progress 🔥 python 🗒️ documentation Improvements or additions to documentation 👀 👀 waiting commiter 👀 👀

Projects

Development

Successfully merging this pull request may close these issues.

4 participants