pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python-attrs/attrs/pull/1602

ll-requests-be6017ec12798e73.css" /> Cache generated method compilation by KRRT7 · Pull Request #1602 · python-attrs/attrs · GitHub
Skip to content

Cache generated method compilation - #1602

Closed
KRRT7 wants to merge 2 commits into
python-attrs:mainfrom
KRRT7:perf/cache-generated-method-compilation
Closed

Cache generated method compilation#1602
KRRT7 wants to merge 2 commits into
python-attrs:mainfrom
KRRT7:perf/cache-generated-method-compilation

Conversation

@KRRT7

@KRRT7 KRRT7 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Cache compiled generated method scripts by script shape to avoid recompiling identical methods for repeated attrs class definitions.

  • Keep the cache bounded at 128 entries.
  • Preserve class-specific traceback and debugger filenames by rewriting cached code objects recursively.
  • Compile cache misses directly with their real filename, avoiding a regression for unique class shapes.

@codspeed-hq

codspeed-hq Bot commented Jul 31, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.9

⚡ 4 improved benchmarks
✅ 13 untouched benchmarks
⏩ 2 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation test_create_cached_property_class 6 s 1.8 s ×3.4
Simulation test_create_frozen_class 4.5 s 1.5 s ×2.9
Simulation test_create_simple_class_make_class 3.5 s 1.2 s ×2.9
Simulation test_create_simple_class 3.7 s 1.4 s ×2.6

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing KRRT7:perf/cache-generated-method-compilation (5c16645) with main (6851ab5)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@hynek

hynek commented Jul 31, 2026

Copy link
Copy Markdown
Member

I think this is an artificial optimization. Unless I'm missing something, it only works when someone keep creating (not instantiating) the same class over and over again. We do that in benchmarks, but that's not something regular codes does. On the flip side, this creates a cache that every class pays for.

@KRRT7

KRRT7 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

it only works when someone keep creating (not instantiating) the same class over and over again.

that exactly was my use case, I'm sure I'm not the only one doing these sort of things, and the cache perf is negligible imo, but can close.

@hynek

hynek commented Aug 1, 2026

Copy link
Copy Markdown
Member

Yeah sorry, I don’t think that’s worth it considering big picture.

@hynek hynek closed this Aug 1, 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.

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy