Skip to content

Add experimental programmatic API for Monty - #4866

Closed
yangdanny97 wants to merge 5 commits into
facebook:mainfrom
yangdanny97:monty-api
Closed

yangdanny97 wants to merge 5 commits into
facebook:mainfrom
yangdanny97:monty-api

Conversation

@yangdanny97

@yangdanny97 yangdanny97 commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

For https://www.github.com/pydantic/monty/pull/501

Something about how Monty can't depend on a crate that's a GH revision hash.

I guess after this gets merged you guys need to publish it, but IDK how to do that

Test Plan

I ran all the tests at some point but after the demise of my Macbook Pro I now use a Macbook Air which has no fans so I'm reluctant to risk running the test suite and overheating it

so, TLDR trust CI

@meta-codesync

meta-codesync Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D119299371. (Because this pull request was imported automatically, there will not be any future comments.)

@yangdanny97 yangdanny97 removed their assignment Sep 9, 2026
@github-actions

This comment has been minimized.

@kinto0 kinto0 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.

somewhat confusing API for an unclear use-case. if we ever merge something like this, I think it needs to be simple and have clear documentation.

I also don't see a disclaimer that this is experimental anywhere in the code

Comment thread pyrefly/lib/embed.rs Outdated
Comment thread pyrefly/lib/embed.rs Outdated
@yangdanny97

Copy link
Copy Markdown
Collaborator Author

In my view this is in the same category as glean's API or the WASM stuff, where it should be undocumented until we refine the API enough and decide to publicize it

The main purpose of merging it is so that Monty can actually release a version that uses Pyrefly

@yangdanny97

Copy link
Copy Markdown
Collaborator Author

Cleaned up a few things

@github-actions github-actions Bot added size/l and removed size/l labels Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@kinto0 kinto0 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.

Review automatically exported from Phabricator review in Meta.

@stroxler stroxler 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.

Review automatically exported from Phabricator review in Meta.

@meta-codesync meta-codesync Bot closed this in 743dec4 Sep 22, 2026
@meta-codesync meta-codesync Bot added the Merged label Sep 22, 2026
@meta-codesync

meta-codesync Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@kinto0 merged this pull request in 743dec4.

meta-codesync Bot pushed a commit that referenced this pull request Sep 25, 2026
Summary:
I took a look at https://github.com/pydantic/monty/pull/501/changes

Running with the latest Pyrefly commit, it seems that perf numbers have regressed with respect to ty. However, Claude suggested this simple fix to `embed.rs` (introduced by yangdanny97  in #4866) which closes the gap. From Claude:

> A check solves one target module over a few small in-memory modules, so the thread pool has nothing to parallelise; dispatching to it and waiting on a futex dominated the cost of a changed-input check (~1.8ms vs ~47us inline on a 20-thread machine). It also meant every embedder process got a pool sized to the machine.

>   `embed::Checker::new` builds its `State` with `ThreadCount::default()`, which is `AllThreads`. Each `check()` solves one target module over
>   a few small in-memory modules, so the pool has nothing to parallelise, and dispatching to rayon and waiting on it costs far more than the
>   check itself. This PR switches the checker to `ThreadCount::Inline`.
>
>   Numbers are from Monty's type-checking benchmarks (one `Checker::check` per iteration), measured with criterion on a 20-thread Linux
>   machine:
>
>   | Benchmark | Before | After | Speedup |
>   |---|---|---|---|
>   | `warm_varying` | 2.09 ms | 48.5 µs | 43× |
>   | `warm_varying_50stubs` | 1.97 ms | 160 µs | 12× |
>   | `repl_sequence` | 8.76 ms | 500 µs | 17× |
>   | `repl_sequence_200` | 548 ms | 163 ms | 3.4× |
>
>   - `warm_varying`: a one-line snippet that changes on every call
>   - `warm_varying_50stubs`: the same, importing a 50-line stub module
>   - `repl_sequence` / `_200`: 4 or 200 REPL steps, with the stubs growing each step
>
>   Before this change, the overhead depends on how many cores the process can use: `warm_varying` takes 2.09 ms on 20 cores, 726 µs on 4 and 68
>   µs on 1 (pinned with `taskset`), compared with 48.5 µs inline. So the cost of a check tracks the machine's core count, not the work done.
>   Embedders that run several checkers at once (Monty runs one per sandbox worker process) also get a full-size pool for each checker.

Fixes #XXXX

Pull Request resolved: #5022

Reviewed By: connernilsen

Differential Revision: D121780342

fbshipit-source-id: 074768e58238fac8af4cccc90b9f0462328a5b6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants