<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Blogs — Alex Polozov
        </title>
        <link>https://alexpolozov.com/blog/</link>
        <description>Recent content in Blogs  — Alex Polozov
        </description>
        <generator>Hugo -- gohugo.io</generator>
        <language>en-us</language>
        <managingEditor>polozov@reflection.ai (Alex Polozov)</managingEditor>
        <webMaster>polozov@reflection.ai (Alex Polozov)</webMaster>
        <lastBuildDate>Thu, 06 Nov 2025 00:00:00 +0000</lastBuildDate>
        
        <atom:link href="https://alexpolozov.com/blog/index.xml" rel="self" type="application/rss+xml" />
        
        
            
            <item>
                <title>Reflection</title>
                <link>https://alexpolozov.com/blog/reflection/</link>
                <pubDate>Thu, 06 Nov 2025 00:00:00 +0000</pubDate>
                <author>polozov@reflection.ai (Alex Polozov)</author>
                <guid>https://alexpolozov.com/blog/reflection/</guid>
                <description>&lt;p&gt;Next week, I am excited to join &lt;a href=&#34;https://reflection.ai&#34; target=&#34;_blank&#34;&gt;Reflection AI&lt;/a&gt; as a Member of Technical Staff to help build the frontier open intelligence ecosystem of the Western world.&lt;/p&gt;

&lt;p&gt;Spending the last few years at Google (X → Labs → DeepMind) during the founding years of the AI revolution was an opportunity of a lifetime. Working on Gemini and Jules with some of the smartest and most ambitious (and fun!) people on Earth &amp;ndash; even more so. I will miss them fondly. But as 2025 unfolded, I found myself reflecting on the state of the AI ecosystem in the U.S. and on my work&amp;rsquo;s impact on empowering software builders&amp;hellip; something critical was missing. This post is my attempt to articulate what.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; This is also my first blog post in&amp;hellip; 7 years, apparently? Most of the older ones were from grad school&lt;/em&gt; 😅 &lt;em&gt;Hope that changes &amp;ndash; I remember enjoying blogging and tweeting about my work, which got somewhat disrupted by the whole &amp;ldquo;highly-confidential-frontier-lab&amp;rdquo; thing.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&#34;ai-as-a-platform-technology&#34;&gt;AI as a platform technology&lt;/h1&gt;

&lt;p&gt;I started my career in programming languages and developer tools. The devtools culture should be an inspiration to all technologists &amp;ndash; they focus less on &lt;em&gt;building a product&lt;/em&gt; and more on &lt;em&gt;building a platform that enables millions of builders to create new products&lt;/em&gt;. What constitutes a &amp;ldquo;platform&amp;rdquo; varies &amp;ndash; Microsoft popularized the desktop OS and SDKs; Amazon popularized cloud computing; Apple popularized mobile apps. We are now in the next, and possibly last, cycle of platform technology &amp;ndash; AI enables all kinds of individuals, tiny teams, or companies to create applications previously thought impossible. It seems to be growing &lt;a href=&#34;https://x.com/levie/status/1887274386492899565?t=MvtJzkuIhGgBA-mz7rcbuQ&amp;amp;s=34&#34; target=&#34;_blank&#34;&gt;faster than any technology in modern history&lt;/a&gt;, with Gemini alone processing &lt;a href=&#34;https://blog.google/products/google-cloud/gemini-enterprise-sundar-pichai/&#34; target=&#34;_blank&#34;&gt;1.3 quadrillion monthly tokens&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But this platform is different &amp;ndash; as a builder, you don&amp;rsquo;t control or fully understand it. Sure, you might not control the binaries of Windows OS or machines in the AWS data center either &amp;ndash; but you &lt;em&gt;understand&lt;/em&gt; the behavior of the components you use. OS APIs are documented and usually deterministic; the VM specs are well-known and can be re-provisioned at will. Not so for an LLM API. You make a black-box call into a model with limited customization (context engineering, sampling parameters, tool definitions, multiturn agent logic) and iterate for a consistently satisfactory result. Often it is. Sometimes not.&lt;/p&gt;

&lt;p&gt;If I were building the next Bloomberg Terminal with AI insights, or AI-driven customer support at a major airline, or a government-contracted public benefits assistant for an EU country&amp;hellip; that level of control and reliability would be unacceptable. Yes, models will improve, but human psychology won&amp;rsquo;t. For any of the above, I would emphasize finetuning my models and owning as much of the stack as I can &amp;ndash; just to derisk. &lt;strong&gt;A good platform empowers competent builders to own, tinker with, and build upon its components.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This realization helps us deduce a few things about the medium-term future:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We shall see a growth of &lt;strong&gt;AI tuning expertise&lt;/strong&gt; &amp;ndash; engineers post-training their own domain- or skill-specialized LLMs. While today &lt;a href=&#34;https://www.latent.space/p/ai-engineer&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;AI Engineer&amp;rdquo;&lt;/a&gt; denotes LLM-aware application building expertise, the next tech cycle will expand it onto LLM post-training too, once again blurring the line with &amp;ldquo;ML Engineer&amp;rdquo;. We can already see that in the &lt;a href=&#34;https://app.primeintellect.ai/dashboard/environments?ex_sort=by_sections&#34; target=&#34;_blank&#34;&gt;blossoming ecosystem of RL environments&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Serious enterprises (e.g., Fortune 500s, hedge funds, sensitive-industry startups, governments) will integrate AI in their applications with more &lt;strong&gt;homegrown models, environments, and evals&lt;/strong&gt;. The art and science of LLM development, currently contained in ~5 frontier labs, will commoditize as a subdiscipline. Specific trade secrets may stay hidden for months or even years &amp;ndash; but the &lt;em&gt;methodology&lt;/em&gt; will spread as soon as the application builders are ready.&lt;/li&gt;
&lt;li&gt;Infrastructure layers of the ecosystem will happily provide for this newfound demand. Jensen Huang is already building 100 of his &lt;a href=&#34;https://www.tomshardware.com/pc-components/gpus/nvidia-is-building-100-ai-factories-jensens-50-year-gambit-begins&#34; target=&#34;_blank&#34;&gt;so-called AI factories&lt;/a&gt; &amp;ndash; data centers specialized for AI, possibly serving individual industries or companies. Serious enterprises will want their homegrown, user-data-tuned AI to &lt;strong&gt;run on-prem or in a leased AI factory&lt;/strong&gt;. A private cloud with an alphabet soup of compliance acronyms won&amp;rsquo;t cut it.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; I am not making any predictions about a hypothetical AGI-assisted world here. The frontier-lab race to develop and own AGI makes a lot of sense, will continue, and, if successful, will change most of the technological tenets of this essay unrecognizably. That won&amp;rsquo;t be easy to &amp;ldquo;control&amp;rdquo;. I reserve any judgements about that world.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;But I think the medium-term road there, using &amp;ldquo;AI as a normal platform technology&amp;rdquo;, looks clearer.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&#34;the-coding-bellwether&#34;&gt;The coding bellwether&lt;/h2&gt;

&lt;p&gt;For evidence of this trend, look at coding 🙂 Code AI has always been a bellwether for our industry &amp;ndash; largely because researchers and engineers love building tools to accelerate ourselves first, and thus it becomes a frontier indicator of AI innovations. Github Copilot was the first successful LLM product, more than a year before ChatGPT. Cursor and Devin were the first useful agents &amp;ndash; reliably completing 10-step tasks months prior to the current wave of travel booking demos.&lt;/p&gt;

&lt;p&gt;So what are Cognition (Devin, Windsurf) and Anysphere (Cursor) doing recently? Training models. Just last week, Cognition released &lt;a href=&#34;https://cognition.ai/blog/swe-1-5&#34; target=&#34;_blank&#34;&gt;SWE-1.5&lt;/a&gt; and Cursor released &lt;a href=&#34;https://cursor.com/blog/composer&#34; target=&#34;_blank&#34;&gt;Composer&lt;/a&gt; &amp;ndash; domain-specialized agentic models finetuned on in-house traces of real-world SWE tasks. Perhaps more interestingly, Cognition also presented &lt;a href=&#34;https://cognition.ai/blog/swe-grep&#34; target=&#34;_blank&#34;&gt;SWE-grep&lt;/a&gt; &amp;ndash; a specialized LLM finetuned for one component of the agentic system, in this case context retrieval. These are our first signs of &lt;em&gt;model innovation&lt;/em&gt; in the agentic app layer, not just software/context/tooling innovation. That will multiply.&lt;/p&gt;

&lt;p&gt;And the second most interesting thing about these models? &lt;a href=&#34;https://x.com/deedydas/status/1984092103358738846&#34; target=&#34;_blank&#34;&gt;They are both built on open Chinese LLMs.&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&#34;we-need-good-western-open-models&#34;&gt;We need good Western open models&lt;/h1&gt;

&lt;p&gt;Finetuning does not require open weights &amp;ndash; all frontier closed-LLM providers have offered tuning APIs for the last ~2 years. However, anecdotally, they have not taken off much:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Iterating on a closed-model finetune is slow, expensive, and can&amp;rsquo;t unlock the full tinkering abilities of an AI engineer. It does not compare to the experimental velocity of your own H100 or DGX SPARK (measured as &lt;em&gt;ablated insights per week&lt;/em&gt; rather than raw hardware throughput).&lt;/li&gt;
&lt;li&gt;For the aforementioned control &amp;amp; ownership reasons, closed models are not even in consideration for serious enterprises. They hope to close the frontier gap with customer data instead. As we are starting to see in coding, that&amp;rsquo;s viable for task- or domain-specialized LLMs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, setting aside the open-vs-closed gap, where are our best open models coming from?



&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/reflection/./open-models-timeline.png&#34;class=&#34;img-responsive center-block&#34; width=&#34;350&#34;/&gt; &lt;/figure&gt;
&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;This chart is from &lt;a href=&#34;https://atomproject.ai/&#34; target=&#34;_blank&#34;&gt;The ATOM Project - American Truly Open Models&lt;/a&gt; manifesto. As of early November 2025, the past six months saw four American open model releases and 14 Chinese ones.&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34;&gt;1&lt;/a&gt;&lt;/sup&gt; The Chinese open models are solid &amp;ndash; while not reaching the state-of-the-art closed-model frontier, they are good enough to build upon and ship to real products (as Windsurf and Cursor successfully demonstrated). The Western alternatives&amp;hellip; less so.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Market adoption is a more important argument that any benchmarks, so &lt;a href=&#34;https://huggingface.co/models?sort=trending&#34; target=&#34;_blank&#34;&gt;HuggingFace Trends&lt;/a&gt; and the Windsurf/Cursor deployments should speak for themselves. But if they don&amp;rsquo;t, look at our favorite marketing datapoint for agents &amp;ndash; &lt;a href=&#34;https://www.swebench.com&#34; target=&#34;_blank&#34;&gt;SWE-bench&lt;/a&gt;. Keeping the harness constant (&amp;ldquo;bash-only&amp;rdquo; minimal agent) and filtering to open-weight models, we have:



&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/reflection/./swebench-bash-only.png&#34;class=&#34;img-responsive center-block&#34; width=&#34;640&#34;/&gt; &lt;/figure&gt;
&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;The 29-point gap between Qwen3-Coder and &lt;code&gt;gpt-oss-120b&lt;/code&gt; is wild. Especially so as the closed Western models (Claude 4.5 Sonnet and GPT-5) range in 65-70% territory (and surpass 80% with bespoke agent harnesses). We don&amp;rsquo;t have &lt;em&gt;comparable&lt;/em&gt; numbers from Llama 4, Magistral, or Command-A, but nobody I know expects them to match Qwen3 or GLM 4.6.&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; Nobody I know is building upon them either.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Does it matter where your open model originates? Even setting aside regulatory and PR risks &lt;em&gt;(which alone are sufficient to discourage most Fortune 500 CTOs, I imagine)&lt;/em&gt;, a Chinese model is a perilous and inconvenient technical choice for an American application stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I prefer reading my model&amp;rsquo;s reasoning traces in a language I understand;&lt;/li&gt;
&lt;li&gt;I prefer to avoid lawsuits about data provenance and copyright choices in my AI features;&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;I don&amp;rsquo;t want to wonder about cultural alignment of my customer-support agent;&lt;/li&gt;
&lt;li&gt;And if I do discover a mismatch, realigning it with company-specific post-training is &lt;em&gt;really hard&lt;/em&gt;. Even frontier labs notoriously struggle training away behavioral quirks all the time, &lt;a href=&#34;https://openai.com/index/sycophancy-in-gpt-4o/&#34; target=&#34;_blank&#34;&gt;OpenAI&amp;rsquo;s sycophancy incident&lt;/a&gt; being the most famous recent example. For enterprise AI engineers, I don&amp;rsquo;t envision alignment as a core competency any time soon, unlike task-oriented post-training.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Put another way, if a Western and an Eastern open model match in performance, any American company should surely pick the former. But we are not even close to such a match.&lt;/p&gt;

&lt;p&gt;This disappointing state of affairs is &lt;strong&gt;obvious to many&lt;/strong&gt;, has existential political connotations to some, and thus obviously going to change. By the end of 2026, I expect at least three strong Western open models on the market, Reflection chiefly among them. &lt;a href=&#34;https://x.com/willccbb/status/1984752065009287582&#34; target=&#34;_blank&#34;&gt;Will Brown predicts 7+&lt;/a&gt; but that might be overly optimistic. After all, there are reasons for the underperformance of Western open models to date &amp;ndash; not for the lack of trying &amp;ndash; and it&amp;rsquo;s hard to predict who will avoid the past mistakes.&lt;/p&gt;

&lt;h2 id=&#34;ingredients&#34;&gt;Ingredients&lt;/h2&gt;

&lt;p&gt;Suppose you decided to capture the open-weight frontier. In 2025-2026, for this recipe you shall need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✔️ Funding for enough compute to supply your staff with experimental velocity. Most of the compute goes to ablations rather than hero runs, so the compute-per-researcher ratio is a more reliable predictor of success than raw FLOPS.&lt;/li&gt;
&lt;li&gt;✔️ A &lt;em&gt;continuous partnership&lt;/em&gt; with a hyperscaler. It&amp;rsquo;s not enough to procure your GPUs once, you must be able to expand compute when you hit milestones, cross-license your models for enterprise serving, benefit from SaaS support and GTM, and rely on the partner for subsequent funding rounds. Reflection has the backing of NVIDIA who was the largest investor in their $2B Series B.&lt;/li&gt;
&lt;li&gt;✔️ Independent company structure from closed frontier. This is ironic, but there are deep organizational reasons why it&amp;rsquo;s difficult for the same lab to lead both closed-weight and open-weight frontiers. I will not elaborate on them. To be fair, Gemma was the best model &lt;em&gt;in its weight class&lt;/em&gt; with every generation, but those classes now lag substantially behind stronger Chinese models. It remains to be seen how the weight classes evolve.&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;&lt;/li&gt;
&lt;li&gt;✔️ Talent. For a foundation-model company, I would overemphasize &lt;em&gt;pretraining&lt;/em&gt;, &lt;em&gt;infrastructure&lt;/em&gt;, &lt;em&gt;evals&lt;/em&gt;, &lt;em&gt;data&lt;/em&gt;, and &lt;em&gt;tool-assisted reasoning&lt;/em&gt; &amp;ndash; in that order of importance. SFT is reasonably well understood; RL is by now probably the hottest research topic in the open-source AI community. But the topics above require expertise with relatively less attention outside frontier labs. Reflection understand this, already has the right talent, and is hiring more 😉&lt;/li&gt;
&lt;li&gt;✔️ Experimental culture. Really, it flows from the right talent and almost religious fervor for the importance of protocol, methodology, ablations, and deep understanding of your evals and vibe checks.&lt;/li&gt;
&lt;li&gt;✔️ Customer obsession. LLMs often fall into a trap of &amp;ldquo;benchmaxxing&amp;rdquo; &amp;ndash; excellent at, say, scientific reasoning but useless for everyday SWE tasks, data wrangling, or automating enterprise workflows. &lt;code&gt;gpt-oss&lt;/code&gt; may be the most famous example. A good foundation-model company is not just a research lab &amp;ndash; it should follow the Startups 101 of &amp;ldquo;know your user needs&amp;rdquo; and build customer relationships early. And if your customers are Fortune 500 enterprises, it helps to live close 🗽&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this time, I only see Thinking Machines, SSI, Reflection, and &lt;em&gt;maybe&lt;/em&gt; Poolside with enough
capitalization to fund all the compute, talent, and data acquisitions. Out of these, Thinky and SSI
are uncertain and stealthy in their product goals, so difficult to analyze. Poolside is now pivoting
toward training foundation models &amp;ndash; but I&amp;rsquo;m unsure about some of the ingredients, plus they haven&amp;rsquo;t mentioned any
commitment to openness to date. Reflection has the partnership with NVIDIA and hits every ingredient
on that list &amp;ndash; with of course lots of work remaining. &lt;strong&gt;It will not be easy, and we&amp;rsquo;ll have plenty
of chances to fail.&lt;/strong&gt; But this is a journey I&amp;rsquo;m actually excited to begin.&lt;/p&gt;

&lt;p&gt;Which brings me to my most important point.&lt;/p&gt;

&lt;h1 id=&#34;join-us&#34;&gt;Join us!&lt;/h1&gt;

&lt;p&gt;You don&amp;rsquo;t have to already know pretraining, or post-training, or GPU training infrastructure, or data curation, or evals &amp;ndash; but of course better if you do 😉 What matters is whether this vision of the beautiful world of independent AI tinkerers, builder empowerment, and open frontier-model science resonates with you. If you&amp;rsquo;d like to contribute your expertise to help make it happen, please by all means drop me a note, we&amp;rsquo;d love to chat. &lt;a href=&#34;https://reflection.ai/careers&#34; target=&#34;_blank&#34;&gt;Reflection is hiring in NYC, SF, and London.&lt;/a&gt;&lt;/p&gt;




&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            
                &lt;img src=&#34;https://cdn.sanity.io/images/irpbdun9/production/195c81f6980bc8e596f30bb4818655e9e27807a5-2560x1920.jpg?crop=center&amp;amp;hotspot=null&amp;amp;w=715&amp;amp;h=536&amp;amp;q=96&amp;amp;fit=crop&amp;amp;auto=format&#34;class=&#34;img-responsive center-block&#34;/&gt; &lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Thanks to Misha Laskin, Ioannis Antonoglou, and Aakanksha Chowdhery for feedback on the early drafts of this post.&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;footnotes&#34;&gt;

&lt;hr /&gt;

&lt;ol&gt;
&lt;li id=&#34;fn:2&#34;&gt;ATOM&amp;rsquo;s timeline omits &lt;a href=&#34;https://docs.cohere.com/docs/command-a&#34; target=&#34;_blank&#34;&gt;Cohere&amp;rsquo;s Command-A&lt;/a&gt; from Canada and &lt;a href=&#34;https://docs.mistral.ai/getting-started/models&#34; target=&#34;_blank&#34;&gt;Mistral&amp;rsquo;s Codestral/Magistral&lt;/a&gt; from France. They don&amp;rsquo;t change the narrative substantially.
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:2&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;li id=&#34;fn:3&#34;&gt;From a brief scan of the SWE-bench Verified leaderboard that &lt;em&gt;does not&lt;/em&gt; control for scaffolding, the closest entrants appear to be DevStral Small 2505 evaluated in the OpenHands harness (46.80%) and Nemotron-CORTEXA, which is a complex parallel-compute harness combining different models for different subtasks (68%). GLM-4.6 achieves the same score with a &lt;del&gt;box of scraps&lt;/del&gt; minimal harness.
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:3&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;li id=&#34;fn:5&#34;&gt;For example &amp;ndash; do we know if GLM 4.6, which Cognition &lt;a href=&#34;https://x.com/deedydas/status/1984092103358738846&#34; target=&#34;_blank&#34;&gt;allegedly&lt;/a&gt; used to post-train their SWE-1.5, properly removed restrictively-licensed code such as GPL from their base model? &lt;a href=&#34;https://arxiv.org/abs/2508.06471&#34; target=&#34;_blank&#34;&gt;Their tech report&lt;/a&gt; does not discuss it. I wonder how the software companies using Windsurf feel about this.
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:5&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;li id=&#34;fn:4&#34;&gt;This is also why I&amp;rsquo;m skeptical of MAI and Grok capturing the open-weight SOTA. Meta, too, has infamously abandoned openness after its MSL/TBD restructuring.
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:4&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description>
            </item>
            
        
            
            <item>
                <title>Program Synthesis in 2017-18</title>
                <link>https://alexpolozov.com/blog/program-synthesis-2018/</link>
                <pubDate>Tue, 10 Jul 2018 00:00:00 -0700</pubDate>
                <author>polozov@reflection.ai (Alex Polozov)</author>
                <guid>https://alexpolozov.com/blog/program-synthesis-2018/</guid>
                <description>&lt;!--
&gt; _This post marks the beginning of a new blog. I’ve been putting off a re-design and re-hosting of this website for the past two years or so, and finally got my hands on it last week._
--&gt;

&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;In early 2017, &lt;a href=&#34;https://www.microsoft.com/en-us/research/people/sumitg/&#34; target=&#34;_blank&#34;&gt;Sumit Gulwani&lt;/a&gt;, &lt;a href=&#34;http://rishabhmit.bitbucket.io&#34; target=&#34;_blank&#34;&gt;Rishabh Singh&lt;/a&gt;, and I wrote a &lt;a href=&#34;https://www.microsoft.com/en-us/research/wp-content/uploads/2017/10/program_synthesis_now.pdf&#34; target=&#34;_blank&#34;&gt;survey on Program Synthesis&lt;/a&gt;. Its goal was to provide a comprehensive overview of the state of the field at the time and to serve as an introduction for newcomers. While complete at the time, the survey got surprisingly outdated in the mere two years. Nowadays, every time someone asks me for an introduction to program synthesis, I point them to this survey but also add 10-20 other links that have recently pushed state of the art. On one hand, this is great: program synthesis is expanding rapidly (ICLR’18 alone had &lt;a href=&#34;https://medium.com/near-ai/program-synthesis-papers-at-iclr-2018-3d3fd3b24464&#34; target=&#34;_blank&#34;&gt;14 papers on the subject&lt;/a&gt;!). On the other hand, I’m getting tired of compiling and annotating these lists of recent links every time 🙂 Ergo, this post — a high-level overview of the recent ideas and representative papers in program synthesis as of mid-2018.&lt;/p&gt;

&lt;p&gt;Before we dive in, a few disclaimers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I assume you are familiar with program synthesis. If not, you&amp;rsquo;re welcome to check out &lt;a href=&#34;https://www.microsoft.com/en-us/research/wp-content/uploads/2017/10/program_synthesis_now.pdf&#34; target=&#34;_blank&#34;&gt;the survey in question&lt;/a&gt; or &lt;a href=&#34;https://homes.cs.washington.edu/~bornholt/post/synthesis-explained.html&#34; target=&#34;_blank&#34;&gt;this excellent blogpost by James Bornholt&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;As expected, it’s impossible to cover everything, although I tried my best. We never set this goal even for the original survey &amp;ndash; there&amp;rsquo;s an enormous body of great work out there. That said, if you notice some glaring omission, please let me know in the comments, and I’ll be happy to include it!&lt;/li&gt;
&lt;li&gt;The list is skewed toward &lt;abbr title=&#34;Machine Learning&#34;&gt;ML&lt;/abbr&gt;/&lt;abbr title=&#34;Artificial Intelligence&#34;&gt;AI&lt;/abbr&gt; rather than &lt;abbr title=&#34;Programming Languages&#34;&gt;PL&lt;/abbr&gt;. This isn&amp;rsquo;t because of any personal biases of mine, but simply because the volume of synthesis-related papers in NIPS/ICLR/ACL/ICML over the last couple of years started exceeding PLDI/POPL/OOPSLA. Many prominent researchers now publish in both communities.&lt;/li&gt;
&lt;li&gt;As with the original survey, I tried to organize the post to highlight high-level ideas rather than individual papers. An idea appears in more than one research paper. I also listed notable individual papers &lt;a href=&#34;#notable-mentions&#34;&gt;in their own section&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Unlike the original survey, this post focuses only on the ideas and techniques, and not on, say, new applications. There&amp;rsquo;s also a small section on &lt;a href=&#34;#datasets&#34;&gt;datasets&lt;/a&gt; in the end.&lt;/li&gt;
&lt;li&gt;There&amp;rsquo;s a fair number of Microsoft Research papers in this list, although I tried my best to maintain diversity.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;neural-guided-search&#34;&gt;Neural-guided search&lt;/h2&gt;

&lt;p&gt;Many program synthesis applications are built on a top-down enumerative search as a means to construct the desired program. The search can be purely enumerative (with some optimizations or heuristics), deductively guided, or constraint-guided. A common theme of many research papers of 2018 has been to augment this search with a learned &lt;em&gt;guiding function&lt;/em&gt;. Its role is to predict, for each branch at each step of the search process, how likely it is to yield a desired program, after which the search can focus only on the likely branches. The guiding function is usually a neural network or some other probabilistic model. The overall setup can be framed slightly differently depending on the interaction of components in the search process, but the key idea of combining a top-down search procedure with a trained model guiding it remains the same.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://arxiv.org/abs/1611.01989&#34; target=&#34;_blank&#34;&gt;DeepCoder&lt;/a&gt; pioneered such combination of symbolic and statistical techniques in early 2017. That system learns a model that, given a task specification (input-output examples in the original work), predicts a &lt;em&gt;distribution over the operators&lt;/em&gt; that may appear in the desired program. This distribution can be then used as a guiding function in any enumerative search.&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:bengio&#34;&gt;&lt;a href=&#34;#fn:bengio&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;




&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/program-synthesis-2018/./ngds.png&#34; alt=&#34;A fragment of the deductive search process looking for the most generalizable program that satisfies the given input-output example. At each branching point in the search tree, the current state is fed into a neural model, which estimates the quality of the best program that is likely to be produced from each branch (shown as a green distribution curve; higher shapes correspond to more promising branches). Source: NGDS.&#34;class=&#34;img-responsive center-block&#34; width=&#34;750&#34;/&gt; &lt;figcaption&gt;
                    
                    &lt;p&gt;
                        A fragment of the deductive search process looking for the most generalizable program that satisfies the given input-output example. At each branching point in the search tree, the current state is fed into a neural model, which estimates the quality of the best program that is likely to be produced from each branch (shown as a green distribution curve; higher shapes correspond to more promising branches). Source: &lt;a href=&#34;https://www.microsoft.com/en-us/research/blog/neural-guided-deductive-search-best-worlds-approach-program-synthesis/&#34; target=&#34;_blank&#34;&gt;NGDS&lt;/a&gt;.
                        
                            
                            &lt;/p&gt;
                    
                &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;The subsequent research in 2017-18 pushed this idea further, allowing the guidance to happen at every step of the search process instead of just its root.
The guidance can now take into account a partial search state instead of just a global task specification.
As expected, this greatly improves the synthesis speed (thanks to trimming down the combinatorial explosion of branches) and accuracy (thanks to the exploration of more promising branches).
The key take-away: if you can obtain enough data to train a reliable guiding function, there’s no reason not to do it, it’ll definitely help the search.
The main &lt;em&gt;caveat&lt;/em&gt; here is that invoking a neural network has a non-zero cost, and sometimes (especially nearing the leaves of the search tree) this can be more expensive than ignoring its prediction and exploring the entire subtree anyway.
Also, if the prediction is wrong, there must be a way to detect this, backtrack, and pick a better branch.
Thus, careful engineering and something like &lt;a href=&#34;https://en.m.wikipedia.org/wiki/A*_search_algorithm&#34; target=&#34;_blank&#34;&gt;A*&lt;/a&gt;, &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Branch_and_bound&#34; target=&#34;_blank&#34;&gt;branch-and-bound&lt;/a&gt;, or &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Beam_search&#34; target=&#34;_blank&#34;&gt;beam search&lt;/a&gt; must be a part of the solution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://www.cis.upenn.edu/~alur/PLDI18.pdf&#39; target=&#34;_blank&#34;&gt;Accelerating Search-Based Program Synthesis using Learned Probabilistic Models&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; PLDI&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Woosuk Lee, Kihong Heo, Rajeev Alur, Mayur Naik&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://openreview.net/pdf?id=HJIHtIJvz&#39; target=&#34;_blank&#34;&gt;Leveraging Constraint Logic Programming for Neural Guided Program Synthesis&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;18 Workshops&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Lisa Zhang, Gregory Rosenblatt, Ethan Fetaya, Renjie Liao, William Byrd, Raquel Urtasun, Richard Zemel&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://alexpolozov.com/papers/iclr2018-neural-guided-search.pdf&#39; target=&#34;_blank&#34;&gt;Neural-Guided Deductive Search for Real-Time Program Synthesis from Examples&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Ashwin Kalyan, Abhishek Mohta, Alex Polozov, Dhruv Batra, Prateek Jain, Sumit Gulwani&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1802.04335&#39; target=&#34;_blank&#34;&gt;Neural Program Search: Solving Programming Tasks from Description and Examples&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;18 Workshops&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Illia Polosukhin, Alexander Skidanov&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://sat-group.github.io/ruben/muse/pldi18.pdf&#39; target=&#34;_blank&#34;&gt;Program Synthesis using Conflict-Driven Learning&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; PLDI&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Yu Feng, Ruben Martins, Osbert Bastani, Isil Dillig&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;sketch-generation&#34;&gt;Sketch generation&lt;/h2&gt;

&lt;p&gt;Human programmers often write a program top-down, first producing a high-level description of the desired program structure, and then concretizing the missing details.
In other words, we often first produce a &lt;a href=&#34;https://people.csail.mit.edu/asolar/manual.pdf&#34; target=&#34;_blank&#34;&gt;sketch&lt;/a&gt; of a program instead of writing the entire program end-to-end. &lt;!--This is presumably because writing the program all in one go is hard, since one would need to choose all the details perfectly on the first try.--&gt;
In program synthesis, manually sketching the desired program has long been a technique of choice for many challenging domains.
However, what if we allow a model to &lt;em&gt;learn&lt;/em&gt; the right sketch?&lt;/p&gt;

&lt;p&gt;The idea of sketch generation is to split the program synthesis process (Spec $\to$ Program) into two phases (Spec $\to$ Sketch $\to$ Program).
The first phase (sketch generation) is usually automatically learned; the second one (program generation) can either be a different learned model or some kind of search.
In either case, in order to train the corresponding model, one defines &lt;strong&gt;(a)&lt;/strong&gt;&amp;nbsp;a language of sketches, &lt;strong&gt;(b)&lt;/strong&gt; an &lt;em&gt;abstraction&lt;/em&gt; function that produces a sketch of a given code snippet, and &lt;strong&gt;(c)&lt;/strong&gt; a dataset of sketches (usually automatically rewritten from a dataset of concrete programs) associated with the corresponding task specs.&lt;/p&gt;




&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/program-synthesis-2018/./coarse2fine.png&#34; alt=&#34;A two-step program generation process, with separate decoder models for (1) a sketch conditioned on the spec and (2) a program conditioned on the sketch and the spec. Source: Coarse2Fine.&#34;class=&#34;img-responsive center-block&#34; width=&#34;750&#34;/&gt; &lt;figcaption&gt;
                    
                    &lt;p&gt;
                        A two-step program generation process, with separate decoder models for (1) a sketch conditioned on the spec and (2) a program conditioned on the sketch and the spec. Source: &lt;a href=&#34;http://homepages.inf.ed.ac.uk/s1478528/acl18-coarse2fine.pdf&#34; target=&#34;_blank&#34;&gt;Coarse2Fine&lt;/a&gt;.
                        
                            
                            &lt;/p&gt;
                    
                &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;Sketch generation outperforms end-to-end program generation.
Intuitively, it is easier for a model to learn high-level patterns of the desired program structure rather than its fine implementation details.
Moreover, filling in implementation details &lt;em&gt;in a given sketch&lt;/em&gt; is much easier than coming up with them on the fly as part of whole program generation.
Thus, non-surprisingly, the technique works pretty well on two very different application domains and specification kinds.&lt;/p&gt;

&lt;p&gt;Sketch generation was developed independently in &lt;a href=&#34;https://arxiv.org/abs/1703.05698&#34; target=&#34;_blank&#34;&gt;Bayou&lt;/a&gt; and &lt;a href=&#34;http://homepages.inf.ed.ac.uk/s1478528/acl18-coarse2fine.pdf&#34; target=&#34;_blank&#34;&gt;Coarse2Fine&lt;/a&gt;.
Bayou takes as input syntactic specs about elements of the desired program (e.g. &lt;em&gt;&amp;ldquo;must include a call to &lt;code&gt;readLines&lt;/code&gt; and an &lt;code&gt;Iterator&lt;/code&gt; type&amp;rdquo;&lt;/em&gt;), and produces &lt;em&gt;the most typical&lt;/em&gt; Java program that includes these elements.
Coarse2Fine takes as input a natural language spec, and produces a snippet that implements it (evaluated on Python and SQL snippets from the Geo, ATIS, Django, and WikiSQL semantic parsing datasets).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;http://homepages.inf.ed.ac.uk/s1478528/acl18-coarse2fine.pdf&#39; target=&#34;_blank&#34;&gt;Coarse-to-Fine Decoding for Neural Semantic Parsing&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ACL&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Li Dong, Mirella Lapata&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1703.05698&#39; target=&#34;_blank&#34;&gt;Neural Sketch Learning for Conditional Program Generation&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Vijayaraghavan Murali, Letao Qi, Swarat Chaudhuri, Chris Jermaine&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;graph-neural-networks&#34;&gt;Graph neural networks&lt;/h2&gt;

&lt;p&gt;Graph Neural Networks, or GNNs, arose recently as a particularly useful architecture for tasks that involve reasoning over source code, including program analysis and program synthesis.
The motivation here is the need to treat a program as an &lt;em&gt;executable object&lt;/em&gt;.
Most of the ML applications to code before 2017 treated programs either as a &lt;em&gt;sequence of tokens&lt;/em&gt; or, at best, &lt;em&gt;a syntax tree&lt;/em&gt;.
This captures natural language-like properties of code, i.e. the patterns that arise in programs thanks to their intent to communicate meaning to other programmers.
However, code also has a second meaning &amp;ndash; it is a formal executable structure, which communicates a particular behavior to the computer.
In other words, NLP-inspired methods, when applied to code, have to infer the semantics of &lt;code&gt;for&lt;/code&gt;, &lt;code&gt;if&lt;/code&gt;, API chaining patterns, and so on.
One would hope that this is learnable by a deep neural network from the ground up, but in practice, &lt;a href=&#34;https://arxiv.org/abs/1410.4615&#34; target=&#34;_blank&#34;&gt;it&amp;rsquo;s been exceedingly difficult&lt;/a&gt;.&lt;/p&gt;




&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/program-synthesis-2018/./gnn.png&#34; alt=&#34;A portion of the data flow graph for a given code snippet, represented with three kinds of auxiliary data flow edges that describe how the variables in the snippet are read and written when the program gets executed. Syntactic AST edges are omitted for clarity. Source: IntelliCode.&#34;class=&#34;img-responsive center-block&#34; width=&#34;750&#34;/&gt; &lt;figcaption&gt;
                    
                    &lt;p&gt;
                        A portion of the &lt;em&gt;data flow graph&lt;/em&gt; for a given code snippet, represented with three kinds of auxiliary data flow edges that describe how the variables in the snippet are read and written when the program gets executed. Syntactic AST edges are omitted for clarity. Source: &lt;a href=&#34;https://www.microsoft.com/en-us/research/blog/learning-source-code/&#34; target=&#34;_blank&#34;&gt;IntelliCode&lt;/a&gt;.
                        
                            
                            &lt;/p&gt;
                    
                &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;A simple way to communicate such information about program semantics to a network is to encode the program&amp;rsquo;s &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Data-flow_analysis&#34; target=&#34;_blank&#34;&gt;data flow graph&lt;/a&gt;.
It enriches the &lt;abbr title=&#34;Abstract Syntax Tree&#34;&gt;AST&lt;/abbr&gt; with additional edges that describe how the information might flow in a typical program execution.
For instance, if a variable &lt;code&gt;x&lt;/code&gt; is read somewhere in the program, we can connect it with all possible locations where &lt;code&gt;x&lt;/code&gt; could have been &lt;em&gt;last written&lt;/em&gt;.
The beauty of the method is that it doesn&amp;rsquo;t care about the semantics of these additional edges, as long as they can be deterministically computed and added to the graph.
For practical tasks (like &lt;a href=&#34;https://www.microsoft.com/en-us/research/blog/learning-source-code/&#34; target=&#34;_blank&#34;&gt;detecting when a variable may be used incorrectly&lt;/a&gt;) the program is augmented with about 10 kinds of such semantic edges.
This augmented graph is then fed into a GNN encoder, which learns the representations for program variables and locations that might be useful for a downstream task, such as variable misuse detection. This is the approach that worked best for a number of software engineering tasks.&lt;/p&gt;

&lt;p&gt;What does it have to do with synthesis? Well, once we’ve established GNNs as a good architecture for processing programs,&lt;sup class=&#34;footnote-ref&#34; id=&#34;fnref:gnn&#34;&gt;&lt;a href=&#34;#fn:gnn&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; then it’s only natural to apply them for program synthesis as well. Recently, we’ve tried to do just that. The idea is to frame program synthesis as a top-down generative model where at each step you &lt;strong&gt;(a)&lt;/strong&gt; decide a grammar production to expand the next “hole” in your partial program, &lt;strong&gt;(b)&lt;/strong&gt; use GNN propagation to update the representations for the relevant nodes of the partial program, &lt;strong&gt;(c)&lt;/strong&gt; refocus and repeat once the entire program is complete. The whole process can be conditioned on any specification, but in our initial experiments we’ve focused on the hardest possible setup – infer a missing program subexpression just from its context, i.e. from surrounding source code alone. That’s &lt;em&gt;hard&lt;/em&gt;. Especially on “real-life” source code (we applied it to various C# subexpressions from popular GitHub projects). We’ve reached 50% top-1 accuracy, which for this kind of setup, I think, is already pretty remarkable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1711.00740&#39; target=&#34;_blank&#34;&gt;Learning to Represent Programs with Graphs&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Miltiadis Allamanis, Marc Brockschmidt, Mahmoud Khademi&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1805.08490&#39; target=&#34;_blank&#34;&gt;Generative Code Modeling with Graphs&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICLR&#39;19&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Marc Brockschmidt, Miltiadis Allamanis, Alexander L. Gaunt, Alex Polozov&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;datasets&#34;&gt;Datasets&lt;/h2&gt;

&lt;p&gt;The recent transition of program synthesis into an AI discipline had another nice side-effect &amp;mdash; a flurry of new datasets.
Neural networks are data-hungry, so researchers are forced to find problems with tens of thousands of data samples, or invent new problems where such a dataset can be creatively generated/collected, and pose a challenge for the field. Sometimes even collecting this dataset can be a genuine ML problem in itself.&lt;/p&gt;




&lt;div class=&#34;figure-container&#34;&gt;
    &lt;figure&gt;
        
            &lt;img src=&#34;https://alexpolozov.com/blog/program-synthesis-2018/./karel.png&#34; alt=&#34;A typical problem from the Karel dataset. The system is given two input-output examples $I_1 \to O_1$, $I_2 \to O_2$, and it has to synthesize a program that also passes a held-out test example $\check{I} \to \check{O}$. Every example is a grid environment for the robot, with walls and markers (potentially of different sizes). Source: Neural Program Meta-Induction.&#34;class=&#34;img-responsive center-block&#34; width=&#34;750&#34;/&gt; &lt;figcaption&gt;
                    
                    &lt;p&gt;
                        A typical problem from the Karel dataset. The system is given two input-output examples $I_1 \to O_1$, $I_2 \to O_2$, and it has to synthesize a program that also passes a held-out test example $\check{I} \to \check{O}$. Every example is a grid environment for the robot, with walls and markers (potentially of different sizes). Source: &lt;a href=&#34;https://arxiv.org/pdf/1710.04157.pdf&#34; target=&#34;_blank&#34;&gt;Neural Program Meta-Induction&lt;/a&gt;.
                        
                            
                            &lt;/p&gt;
                    
                &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/div&gt;

&lt;p&gt;Here are some datasets that the community has lately focused on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two new semantic parsing (English $\to$ Python) datasets, collected from StackOverflow: &lt;a href=&#34;https://github.com/LittleYUYU/StackOverflow-Question-Code-Dataset&#34; target=&#34;_blank&#34;&gt;StaQC&lt;/a&gt; and &lt;a href=&#34;https://conala-corpus.github.io/&#34; target=&#34;_blank&#34;&gt;CoNaLa&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://msr-redmond.github.io/karel-dataset/&#34; target=&#34;_blank&#34;&gt;Karel&lt;/a&gt;, a toy robot programming language that used be to used for introductory programming classes at Stanford. The dataset contains synthetically generated programs, each with 5 input-output examples.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://near.ai/research/naps/&#34; target=&#34;_blank&#34;&gt;NAPS&lt;/a&gt;, a really young and quite challenging dataset containing preprocessed problems from algorithmic competitions along with imperative descriptions and examples.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/salesforce/WikiSQL&#34; target=&#34;_blank&#34;&gt;WikiSQL&lt;/a&gt;, a large semantic parsing dataset (English $\to$ limited SQL). It&amp;rsquo;s a bit controversial due to its &lt;a href=&#34;https://arxiv.org/abs/1806.09029&#34; target=&#34;_blank&#34;&gt;lack of program variety&lt;/a&gt; and semi-artificial language generation, but its size and variety of tables/questions has generated a lot of attention after Salesforce released it a year ago.&lt;/li&gt;
&lt;li&gt;A &lt;a href=&#34;https://arxiv.org/abs/1806.09029&#34; target=&#34;_blank&#34;&gt;standardized collection&lt;/a&gt; of 10 semantic parsing datasets from NLP and DB communities, preprocessed into SQL instead of various logical forms.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;notable-mentions&#34;&gt;Notable mentions&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1703.07469&#39; target=&#34;_blank&#34;&gt;RobustFill: Neural Program Learning under Noisy I/O&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICML&#39;17&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Jacob Devlin, Jonathan Uesato, Surya Bhupatiraju, Rishabh Singh, Abdel-rahman Mohamed, Pushmeet Kohli&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An end-to-end differentiable version of FlashFill that&amp;rsquo;s trained on a large volume of synthetically generated tasks and can adapt to small noise in the input-output examples. The core architecture is surprisingly simple, but works well for its DSL. Demonstrates an unreasonable effectiveness of attention 🙂&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://sat-group.github.io/ruben/muse/pldi18.pdf&#39; target=&#34;_blank&#34;&gt;Program Synthesis using Conflict-Driven Learning&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; PLDI&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Yu Feng, Ruben Martins, Osbert Bastani, Isil Dillig&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition to a variant of &lt;a href=&#34;#neural-guided-search&#34;&gt;statistical branch prioritization&lt;/a&gt;, this paper introduces the notion of &lt;em&gt;conflict-driven search&lt;/em&gt; from SAT/SMT solving to the program synthesis world.
Loosely speaking, in modern SAT/SMT search algorithms, when a search branch results in a failure, we can learn a &lt;em&gt;reason&lt;/em&gt; for this failure &amp;ndash; a new &lt;em&gt;conflict clause&lt;/em&gt; (i.e., a particular contradiction) that can be added to the working set of constraints to avoid a similar mistake in the future.
In contrast, search algorithms in program synthesis couldn&amp;rsquo;t do that &amp;mdash; until now.
Now, for instance, an input-output example $[1, 2, 3] \to [2, 4]$ not only immediately eliminates any program of form &lt;code&gt;x =&amp;gt; map(x, ...)&lt;/code&gt; (because &lt;code&gt;map&lt;/code&gt; can&amp;rsquo;t change the length of its input list), but also generates a constraint that eliminates &lt;code&gt;x =&amp;gt; reverse(x, ...)&lt;/code&gt; and &lt;code&gt;x =&amp;gt; sort(x, ...)&lt;/code&gt; for the same reason.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://papers.nips.cc/paper/7845-learning-to-infer-graphics-programs-from-hand-drawn-images&#39; target=&#34;_blank&#34;&gt;Learning to Infer Graphics Programs from Hand-Drawn Images&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; NeurIPS&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Kevin Ellis, Daniel Ritchie, Armando Solar-Lezama, Joshua B. Tenenbaum&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A neat paper that introduces a novel program synthesis problem (recovering $\mathrm{\LaTeX}$ programs from hand-drawn mock-ups) that nicely combines perceptual and symbolic techniques. There are many technical challenges: dealing with noise in the input, recovering the right primitives, optimizing the resulting constraint problem with a learned policy, and so on.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;div class=&#34;pubref&#34;&gt;
    &lt;div&gt;
        &lt;a href=&#39;https://arxiv.org/abs/1804.02477&#39; target=&#34;_blank&#34;&gt;Programmatically Interpretable Reinforcement Learning&lt;/a&gt;
        &lt;span style=&#34;margin: 0 1.5rem;&#34; class=&#34;text-muted&#34;&gt;&lt;small&gt;&lt;i class=&#34;fas fa-newspaper&#34;&gt;&lt;/i&gt; ICML&#39;18&lt;/small&gt;&lt;/span&gt;
    &lt;/div&gt;
    &lt;div style=&#34;margin-top: -0.6rem;&#34;&gt;
        &lt;small&gt;Abhinav Verma, Vijayaraghavan Murali, Rishabh Singh, Pushmeet Kohli, Swarat Chaudhuri&lt;/small&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Have you ever wanted to understand the behavior of your learned &lt;abbr title=&#34;Reinforcement Learning&#34;&gt;RL&lt;/abbr&gt; policy?
Or maybe not 100% &lt;em&gt;understand&lt;/em&gt;, but at least &lt;em&gt;get some insight&lt;/em&gt; into its logic, or maybe &lt;em&gt;replace&lt;/em&gt; its logic with something more interpretable and generalizable.
Turns out, program synthesis can help.
The method is straightforward and beautiful in its simplicity: train a policy to, say, drive a race car, and then search for a program in an appropriate DSL to approximate the behavior of this policy.
(The devil, of course, is in the details: DSL design, good sketches, and a method to intelligently sample examples from the policy are all key to making this work.)
The program is not as perfectly optimized for the fastest track completion as a neural policy, but it drives smoother, provably generalizes to other tracks, and, most importantly, you can read it.
All these benefits become apparent in a video.&lt;/p&gt;

&lt;div class=&#34;embed-responsive embed-responsive-16by9&#34;&gt;
    &lt;iframe class=&#34;embed-responsive-item&#34; src=&#34;https://drive.google.com/file/d/1s1pGcYUavpjBirwwwJnngkizuLkkAcL3/preview&#34;
            width=&#34;853&#34; height=&#34;480&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;div class=&#34;footnotes&#34;&gt;

&lt;hr /&gt;

&lt;ol&gt;
&lt;li id=&#34;fn:bengio&#34;&gt;With sincere apologies to Yoshua Bengio, who hasn’t been asked for consent to using his name in the illustrations. We all know how hard it is to make new figures, so the choices you make in a preprint often live on in posters, talks, and blog posts. 🙂
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:bengio&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;li id=&#34;fn:gnn&#34;&gt;I’ve heard people say that GNNs are to programs are what CNNs are to images and LSTMs are to text — if not necessarily a silver bullet, then at least a baseline architecture of choice. I personally think it’s not as clear-cut yet, but explicit reasoning over graphs and relations should definitely be involved in most AI tasks out there.
 &lt;a class=&#34;footnote-return&#34; href=&#34;#fnref:gnn&#34;&gt;↩&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</description>
            </item>
            
        
            
            <item>
                <title>On performance in .NET</title>
                <link>https://alexpolozov.com/blog/on-performance-in-dotnet/</link>
                <pubDate>Sun, 28 Sep 2014 21:41:39 -0700</pubDate>
                <author>polozov@reflection.ai (Alex Polozov)</author>
                <guid>https://alexpolozov.com/blog/on-performance-in-dotnet/</guid>
                <description>&lt;p&gt;Formerly, when someone asked me &amp;ldquo;How to make my C# program faster?&amp;rdquo;, my go-to advice was:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improve your &lt;a href=&#34;http://en.wikipedia.org/wiki/Computational_complexity_theory&#34; target=&#34;_blank&#34;&gt;computational complexity&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Switch to a native language.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Of these suggestions, step #1 should take care of performance in most situations, if done properly. However,
sometimes it is not enough. For example, you are writing a user-facing real-time performance-critical
application, such as the
&lt;a href=&#34;http://roslyn.codeplex.com&#34; target=&#34;_blank&#34;&gt;C# compiler&lt;/a&gt;, and you need to look not only at the average performance, but at
the 99&lt;sup&gt;th&lt;/sup&gt; percentile. This is where step #2 used to take over&amp;hellip; but not anymore. Currently, my
go-to advice looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Improve your computational complexity.

&lt;ol&gt;
&lt;li&gt;Read &lt;a href=&#34;http://www.writinghighperf.net/&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;Writing High-Performance .NET Code&amp;rdquo;&lt;/a&gt;, Roslyn team blog, and the rest of the links provided below.&lt;/li&gt;
&lt;li&gt;Switch to a native language.&lt;/li&gt;
&lt;/ol&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&#34;measurement-tools&#34;&gt;Measurement tools&lt;/h2&gt;

&lt;p&gt;&lt;a href=&#34;http://www.writinghighperf.net/&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;Writing High-Performance .NET Code&amp;rdquo;&lt;/a&gt; should be your desk book for any performance-critical .NET application. I found the following knowledge it provides most important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What profiling tools exist in the .NET world (PerfView, ETW, CLR Profiler, dotTrace, dotMemory, Windbg&amp;hellip;), how to use each one of them, how to answer specific questions with a combination of these tools, which metrics should you look at and why.&lt;/li&gt;
&lt;li&gt;How &lt;em&gt;exactly&lt;/em&gt; .NET GC works and why you should care. How to help .NET GC by managing your allocations and object lifecycle carefully.&lt;/li&gt;
&lt;li&gt;JIT mechanics, NGEN, when to use each of them, startup rates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In other words, when you have a specific problem with your .NET application, this book will show how to use the tools to locate who exactly is responsible for the bottleneck, how often it occurs, and so on. Often you will be surprised, because (assuming you&amp;rsquo;ve already gone through step #1) your greatest bottleneck is going to be either GC, allocations, JIT, boxing, or incorrect usage of .NET API. All of these subtle engineering details are quite unobvious if you don&amp;rsquo;t train yourself to keep them in mind.&lt;/p&gt;

&lt;h2 id=&#34;performance-minded-coding&#34;&gt;Performance-minded coding&lt;/h2&gt;

&lt;p&gt;When you know the &lt;em&gt;consequence&lt;/em&gt; of the problem (e.g. &amp;ldquo;my app spends 20% of the time in GC&amp;rdquo;, which arises because of &amp;ldquo;there&amp;rsquo;s this pinned handle that points to a long retention path that is being walked on every gen-2 collection&amp;rdquo;), the next step is to eliminate it. The series of links below (along with the accompanying chapters in &lt;a href=&#34;http://www.writinghighperf.net/&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;Writing High-Performance .NET Code&amp;rdquo;&lt;/a&gt;) explains the techniques for doing it. If you &lt;em&gt;know&lt;/em&gt; that this particular path in your code is going to be performance-critical up to the 99&lt;sup&gt;th&lt;/sup&gt; percentile (never optimize prematurely!), you should really think of these techniques as guiding principles to keep in mind every second during your coding process.&lt;/p&gt;

&lt;p&gt;Here are some must-read articles for any .NET programmer that works with performance-critical code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=uqFSjNqgT-I&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;Essential Truths Everyone Should Know about Performance in a Large Managed Codebase&amp;rdquo;&lt;/a&gt; &amp;mdash; this BUILD 2013 talk was done by Dustin Campbell, a program manager on the Visual Studio/Roslyn team. In it, Dustin discusses the techniques they used when they rewrote the VB.NET/C# compiler from C++ to C# to make the new version perform almost as fast as the native one.
&lt;div class=&#34;row text-center&#34;&gt;
    &lt;div style=&#34;embed-responsive embed-responsive-16by9&#34;&gt;
        &lt;iframe width=&#34;560&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/uqFSjNqgT-I&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;/iframe&gt;
    &lt;/div&gt;
&lt;/div&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;&amp;ldquo;Roslyn code base – performance lessons&amp;rdquo; (&lt;a href=&#34;http://mattwarren.org/2014/06/05/roslyn-code-base-performance-lessons-part-1/&#34; target=&#34;_blank&#34;&gt;part 1&lt;/a&gt;, &lt;a href=&#34;http://mattwarren.org/2014/06/10/roslyn-code-base-performance-lessons-part-2/&#34; target=&#34;_blank&#34;&gt;part 2&lt;/a&gt;) &amp;mdash; written by Matt Warren, an enthusiast who looked through the open-sourced Roslyn code, and outlined even more tecnhiques from the codebase in a series of blog articles.&lt;/li&gt;
&lt;li&gt;Really, you should read the entire &lt;a href=&#34;http://mattwarren.org/&#34; target=&#34;_blank&#34;&gt;Matt&amp;rsquo;s blog&lt;/a&gt;, it is full of performance wisdom.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://samsaffron.com/archive/2011/10/28/in-managed-code-we-trust-our-recent-battles-with-the-net-garbage-collector&#34; target=&#34;_blank&#34;&gt;&amp;ldquo;In managed code we trust, our recent battles with the .NET Garbage Collector&amp;rdquo;&lt;/a&gt; &amp;mdash; this article is from the StackOverflow team, and it tells a similar performance investigation story. It&amp;rsquo;s interesting to see how they tracked down the issue and what did they do to eliminate it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I&amp;rsquo;m going to list some of the mentioned techniques below, briefly. Again, the book and the sources above have already done it much better than me.&lt;/p&gt;

&lt;h3 id=&#34;avoid-allocations&#34;&gt;Avoid allocations&lt;/h3&gt;

&lt;p&gt;For every allocation you make, the .NET GC will spend a little more time on every future collection. If this instance is relatively long-lived, it&amp;rsquo;s going to eventually move to gen-1 and gen-2, and greatly affect the future GC times. But even if it is short-lived, the performance of gen-0 collection is going to matter in your higher percentiles anyway.&lt;/p&gt;

&lt;p&gt;Some of the common sources of hidden allocations are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LINQ queries: they allocate enumerators and lambda-representing objects that capture references in a closure. Also, eventually you need to convert a query to a list/array, and it&amp;rsquo;s going to expand itself several times in the process. Instead you should allocate a list/array of a known capacity beforehand, and do all the required work directly, without allocating hidden LINQ enumerators.&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Lambdas: if they capture any references from the outer scope, they will be rewritten to compiler-generated objects. If your lambda operates in a generic context this object will not even be cached in place, and will be re-created every time. Consider refactoring your logic in such a way that lambda becomes non-capturing (such lambdas compile down to static methods), or get rid of the lambda altogether.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;UPD:&lt;/strong&gt; This behavior will change in the upcomping C# 6. In Roslyn, &lt;a href=&#34;https://roslyn.codeplex.com/workitem/246&#34; target=&#34;_blank&#34;&gt;lambda functions now always compile down to instance calls&lt;/a&gt;, which causes up to 35% performance gain in common scenarios.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Strings: because they are immutable, every string modification allocates a new string object. This is most subtle in calls like &lt;code&gt;string.Trim(&#39; &#39;)&lt;/code&gt;, which actually returns a &lt;em&gt;new&lt;/em&gt; string. Instead use index-based arithmetic on hot paths. For case-insensitive comparison, use the corresponding &lt;code&gt;string.Compare&lt;/code&gt; overload instead of converting all your strings to lowercase with &lt;code&gt;string.ToLower&lt;/code&gt;. Also, string concatenation for simple cases is much faster than string formatting.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Invoking a method with &lt;code&gt;params&lt;/code&gt; always allocates an array, possibly of zero length. Consider creating specialized overloads for most common numbers of parameters.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;use-object-pooling&#34;&gt;Use object pooling&lt;/h3&gt;

&lt;p&gt;If you use some objects often but temporarily, consider allocating a pool of objects of this type once, and reuse them where necessary. For example, the interface that Roslyn uses for &lt;code&gt;StringBuilder&lt;/code&gt;s look somewhat like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-cs&#34; data-lang=&#34;cs&#34;&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;internal&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;StringBuilderPool&lt;/span&gt; {
    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; StringBuilder Allocate() {
        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; SharedPools.Default&amp;lt;StringBuilder&amp;gt;().AllocateAndClear();
    }
 
    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;void&lt;/span&gt; Free(StringBuilder builder) {
        SharedPools.Default&amp;lt;StringBuilder&amp;gt;().ClearAndFree(builder);
    }
 
    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;string&lt;/span&gt; ReturnAndFree(StringBuilder builder) {
        SharedPools.Default&amp;lt;StringBuilder&amp;gt;().ForgetTrackedObject(builder);
        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; builder.ToString();
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Which is then later used in the following manner:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-cs&#34; data-lang=&#34;cs&#34;&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;override&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;string&lt;/span&gt; GetTextBetween(SyntaxToken token1, SyntaxToken token2) {
    &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; builder = StringBuilderPool.Allocate();
    CommonFormattingHelpers.AppendTextBetween(token1, token2, builder);
    &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; StringBuilderPool.ReturnAndFree(builder);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;compile-your-reflection-calls-into-delegates&#34;&gt;Compile your reflection calls into delegates&lt;/h3&gt;

&lt;p&gt;Method calling through Reflection is horrendously slow. If you know the signature of your method beforehand (and for some reason cannot agree on a common interface with the third party who implements the external method), you can use &lt;a href=&#34;http://msdn.microsoft.com/en-us/library/bb397951.aspx&#34; target=&#34;_blank&#34;&gt;LINQ Expression Trees&lt;/a&gt; to compile your &lt;code&gt;MethodInfo&lt;/code&gt; to a strongly-typed delegate. This needs to be done only once, after that you can keep a reference to the delegate, and call it whenever necessary with standard C# syntax.&lt;/p&gt;

&lt;p&gt;The technique is described at &lt;a href=&#34;http://codeblog.jonskeet.uk/2008/08/09/making-reflection-fly-and-exploring-delegates/comment-page-1/#comment-10325&#34; target=&#34;_blank&#34;&gt;Jon Skeet&amp;rsquo;s blog&lt;/a&gt;. Here&amp;rsquo;s how I used it in one of my recent projects:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-cs&#34; data-lang=&#34;cs&#34;&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;static&lt;/span&gt; TDelegate ToDelegate&amp;lt;TDelegate&amp;gt;(&lt;span style=&#34;color:#66d9ef&#34;&gt;this&lt;/span&gt; MethodInfo method) {
     &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; parameterTypes = method.GetParameters().Select(p =&amp;gt; p.ParameterType).ToArray();
     MethodInfo invokeMethod = &lt;span style=&#34;color:#66d9ef&#34;&gt;typeof&lt;/span&gt; (TDelegate).GetMethod(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Invoke&amp;#34;&lt;/span&gt;);
     &lt;span style=&#34;color:#66d9ef&#34;&gt;var&lt;/span&gt; @params = invokeMethod.GetParameters()
                               .Select((p, i) =&amp;gt; Expression.Parameter(p.ParameterType, &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;arg&amp;#34;&lt;/span&gt; + i))
                               .ToArray();
     MethodCallExpression methodCall = Expression.Call(method,
         @params.ZipWith(parameterTypes).Select2(Expression.Convert));
     &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; Expression.Lambda&amp;lt;TDelegate&amp;gt;(Expression.Convert(methodCall, invokeMethod.ReturnType), @params).Compile();
 }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id=&#34;avoid-boxing&#34;&gt;Avoid boxing&lt;/h3&gt;

&lt;p&gt;Apart from obvious cases where people unnecessarily convert value types into objects (such as using now deprecated &lt;a href=&#34;http://msdn.microsoft.com/en-us/library/system.collections%28v=vs.110%29.aspx&#34; target=&#34;_blank&#34;&gt;System.Collections&lt;/a&gt; namespace), there are some subtler ones:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;String.Format&lt;/code&gt; boxes its arguments&lt;/li&gt;
&lt;li&gt;Structs are boxed when used through their implemented interface. In particular, this happens when you use LINQ: &lt;code&gt;List&amp;lt;T&amp;gt;.Enumerator&lt;/code&gt; is a struct, but LINQ methods treat it as &lt;code&gt;IEnumerator&amp;lt;T&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Object.Equals(object other)&lt;/code&gt; is the source of all evil&lt;/li&gt;
&lt;li&gt;Do not &lt;em&gt;ever&lt;/em&gt; concatenate a string with anything other than a string&lt;/li&gt;
&lt;li&gt;Calling &lt;code&gt;GetHashCode&lt;/code&gt; on an enum causes boxing. Convert the enum instance to &lt;code&gt;int&lt;/code&gt; first.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;use-specialized-collections-for-smaller-sizes&#34;&gt;Use specialized collections for smaller sizes&lt;/h3&gt;

&lt;p&gt;An array outperforms a dictionary up to a certain number of elements, even though its lookup is $\mathcal{O}(n)$. The reason is all the boilerplate overhead that accompanies a dictionary (hashtable, bucket exploration, etc.). The exact tripping point depends on your particular code and has to be measured experimentally.&lt;/p&gt;

&lt;h3 id=&#34;know-when-to-use-structs-and-when-not-to&#34;&gt;Know when to use structs and when not to&lt;/h3&gt;

&lt;p&gt;Structs give better performance than classes when they are small, consist of primitive types, and when they are not copied around often. The overhead of a class vtable is noticeable during garbage collection. However, classes are copied faster, because they are represented with just a pointer. On another hand, an array of classes will cause you a nightmare of cache misses (see &lt;a href=&#34;http://en.wikipedia.org/wiki/Locality_of_reference&#34; target=&#34;_blank&#34;&gt;reference locality&lt;/a&gt;). An array of structs neatly lies in memory as a single block, but would be a nightmare to copy as a function result. Bottom line, know your usecase and measure everything.&lt;/p&gt;

&lt;p&gt;Note: you should &lt;em&gt;always&lt;/em&gt; re-implement &lt;code&gt;Equals&lt;/code&gt;, &lt;code&gt;GetHashCode&lt;/code&gt;, and &lt;code&gt;IEquatable&amp;lt;T&amp;gt;.Equals&lt;/code&gt; for your structs, because the default implementations use reflection to enumerate over the fields.&lt;/p&gt;

&lt;h3 id=&#34;compile-your-regular-expressions&#34;&gt;Compile your regular expressions&lt;/h3&gt;

&lt;p&gt;If you are going to reuse the same regular expression often, build it with a &lt;code&gt;RegexOptions.Compiled&lt;/code&gt; flag. Do not ever use static methods of the &lt;code&gt;Regex&lt;/code&gt; class, they are horrendously slow.&lt;/p&gt;

&lt;p&gt;If your regular expressions do not require non-regular features such as lookaround or backreferences, consider using &lt;a href=&#34;https://code.google.com/p/re2/&#34; target=&#34;_blank&#34;&gt;re2&lt;/a&gt; instead of a default regex engine. It might yield you up to a 10x speedup. There is a .NET wrapper available, called &lt;a href=&#34;https://github.com/0xcb/Re2.Net/tree/master/Re2.Net&#34; target=&#34;_blank&#34;&gt;Re2.Net&lt;/a&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I will stop here because I cannot possibly outline all of the techniques. Again, for the complete picture read the book, watch the talk, read the articles referenced above, know your tools, and measure everything carefully. Also, feel free to comment here if you want to contribute more advice!&lt;/p&gt;</description>
            </item>
            
        
    </channel>
</rss>