Skip to content

Conversation

Copy link

Copilot AI commented Oct 7, 2025

Overview

This PR establishes a structured experimental framework for testing and documenting piecemeal optimizations to Clojure's syntax-quote reader. The work is organized to support the Clojure contribution process and addresses concerns raised in CLJ-2908.

Background

This work is part of https://clojure.atlassian.net/browse/CLJ-2908[CLJ-2908: Optimize syntax-quote], which proposed comprehensive optimizations but was determined to be too broad in scope. This project splits the work into smaller, focused experiments to make more persuasive cases for individual optimizations. Many specific optimizations we're testing were originally proposed in https://clojure.atlassian.net/browse/CLJ-1506[CLJ-1506: Optimize some syntax-quote cases], which may be repurposed for our initial work.

Project Structure

All experimental work is organized under syntax-quote-optimization/ (treated as the project root):

syntax-quote-optimization/
├── README.adoc                      # Project overview and JIRA context
├── optimize-syntax-quote.md         # Technical motivation document
├── nil-optimization/                # First subproject
│   ├── nil-optimization.patch       # Git patch applying to Clojure 1.12.3
│   ├── build-optimized-uberjar.sh  # Shared reproducible build script
│   ├── README.adoc                  # Subproject documentation
│   └── experiments/
│       ├── uberjar-comparison/      # Overall JAR size impact
│       └── if-not-macro/            # Focused if-not macro analysis
└── (future optimization subprojects...)

Key Changes

  • Created git patch for nil optimization (applies cleanly to e6393a4 / Clojure 1.12.3)
  • Organized all work under syntax-quote-optimization/ directory
  • No Clojure source modifications in branch - optimizations applied via git patches only
  • Moved planning documents (optimize-syntax-quote.md) into project directory
  • Created shared build-optimized-uberjar.sh script that clones official Clojure repo
  • Updated all experiment scripts to use shared builder
  • Organized experiments into subprojects (nil-optimization) with sub-experiments
  • Added comprehensive documentation with JIRA ticket context (CLJ-2908, CLJ-1506)
  • Updated GitHub Actions workflow for new structure

Nil Optimization (Current)

The first experiment focuses on making nil self-evaluating in syntax-quote, centered on the if-not macro as a minimal example.

Patch: Single line change adding || form == null to LispReader.java

Experiments:

  1. Uberjar comparison - Measures overall impact on Clojure JAR size
  2. if-not macro analysis - Detailed bytecode, performance, and semantic analysis with three reproducible verification scripts

Methodology

Each optimization follows a consistent workflow:

  1. Create minimal git patch applying to specific Clojure release
  2. Build optimized JARs using reproducible scripts (clones official repo + applies patch)
  3. Measure impact at multiple levels
  4. Document results with verification scripts
  5. Verify artifacts with SHA256 checksums

JIRA Context

  • CLJ-2908: Overarching syntax-quote optimization ticket (split due to scope)
  • CLJ-1506: Proposes specific optimizations (nil, booleans, empty collections) - may be repurposed

Status

Complete! Framework established with nil optimization as first experiment. All work organized for Clojure contribution process with git patches ready for submission.

Original prompt

I was working with copilot and it stopped recognizing my prompts, claiming it could not find new comments. My attempt at working around this problem is to start a new agent task here. Please reconstruct the conversation in this PR and start working on this PR comment @frenchy64/clojure/pull/43 (starting with "we need a more focussed report about the nil optimization").


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits October 7, 2025 18:59
Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor nil optimization report for clarity and focus Focus nil optimization analysis on if-let macro with reproducible verification scripts Oct 7, 2025
Copilot AI requested a review from frenchy64 October 7, 2025 19:04
@frenchy64
Copy link
Owner

frenchy64 commented Oct 7, 2025

@copilot this is very promising. I would like some changes.

  1. I realized that if-not is a more minimal macro than if-let, so it's more appropriate for this analysis. Please change your report and scripts to analyze the effect of the optimization on if-not instead of if-let. If you can think of a more appropriate and even smaller macro for this analysis, please suggest it in your response in the PR and I will consider it.
  2. There are some markdown syntax problems. Because we're using the backtick so much, markdown is actually failing to syntax-highlight things correctly. Please use a different documentation format that better supports inline code containing backticks like adoc to write these documents, and double check that the code blocks will display correctly.
  3. In the "Technical Details" section of the report, from a reader's perspective there is a disconnect between the claimed differences and the scripts that verify them. Please be as precise here a possible. Let's try and put the relevant diffs directly into the document, because the scripts are too large to easily find them. You can embellish the diffs by adding end-of-line "comments" explaining what each bytecode does, and the key differences on a semantic level. Please combine this section with the previous section "Verification Scripts" and be more precise in referencing the line numbers in each script when you point out diffs. Keep the structure of discussing the 3 different scenarios, but combine the respective sections so the scripts have the quality of more of a footnote or appendix.

Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 7, 2025

@copilot this is very promising. I would like some changes.

  1. I realized that if-not is a more minimal macro than if-let, so it's more appropriate for this analysis. Please change your report ...

Changes implemented in commit above:

  1. Changed to if-not macro: More minimal than if-let - only 2 forms (2-arity and 3-arity), no binding complexity. The 2-arity version directly uses pass:[nil]: (if-not ~test ~then nil)`. This is the simplest possible example.

  2. Converted to AsciiDoc format: New file IF_NOT_NIL_OPTIMIZATION_ANALYSIS.adoc uses AsciiDoc which properly handles inline code containing backticks via pass:[] macro. Code blocks display correctly without markdown syntax issues.

  3. Combined sections with precise diffs: Technical Details now includes:

    • Exact bytecode diffs with inline comments (lines 88-130 in compare script)
    • Performance measurement code (lines 69-82 in measure script)
    • Test code with line references (lines 56-112 in verify script)
    • Each diff shows BEFORE/AFTER with semantic explanations

All scripts renamed and updated to use if-not. Directory renamed to if-not-nil-scripts/.

Copilot AI changed the title Focus nil optimization analysis on if-let macro with reproducible verification scripts Focus nil optimization analysis on if-not macro with reproducible verification scripts Oct 7, 2025
@frenchy64 frenchy64 changed the base branch from optimize-syntax-quote to master October 7, 2025 19:42
@frenchy64 frenchy64 changed the base branch from master to clojure-branch-1-12-3 October 7, 2025 19:49
@frenchy64
Copy link
Owner

@copilot there is a problem. The tests were being run under the optimize-syntax-quote branch, which contains all the syntax-quote optimizations. We need to run the tests under the minimal changes of just optimizing syntax-quoting nil. I've changing the base branch of this PR to a branch that will always point to the e6393a4 which is the commit that Clojure 1.12.3 was released from. In the end, Clojure's contribution process uses git patch files, so I'd like to you to start preparing git patches instead of committing the optimizations to the branch. This is for two reasons. One, so we are better prepared to contribute to Clojure. Two, so we can have more than one experiment in this repository. So please find the isolated syntax-quote optimization for nil again (hint: it's just a single line of Java adding an == to a disjunction, you may need to look in the optimize-syntax-branch or I think it's mentioned in one of the documents in this repo). I want you to commit a git patch to this repository that cleanly applies to commit e6393a4 using standard git tooling for applying patches. Then update your scripts to build the uberjar by cloning this commit from the official Clojure repository, then applying the patch with the minimal optimization, then using that directory to generate the uberjar. Just ignore that we're in a fork of the Clojure repo, we should have really started a fresh project for this. I'll do that later. Just treat this copilot/improve-nil-optimization-report branch as an empty project in practice, don't commit modifications to Clojure's source code in this branch (we'll clone Clojure and apply a git patch that we've committed to copilot/improve-nil-optimization-report instead). So actually, changing the base of this PR doesn't matter in the end, oh well :). As usual, please double check this all works by testing it and iterating on it yourself before pushing.

I would like for you to reorganize our work so far. Everything related to the optimization should go into a new folder called something like syntax-quote-optimization. Of course, keep the GitHub Actions in the correct workflows directory. Move the documents that describe and plan this overall project of merging syntax quote optimizations at the top-level of this directory. Then separate the different experiments in directories under this folder. I like the overall plan you laid out of trying successively larger experiments. Use this plan to help organize (name/number) the experiments' directories. At the moment we have one overall "subproject" (our first): the nil optimizations for syntax quote. We have two categories of experiments under this: testing the overall effects of on the uberjar, and the specific effects on the if-not macro. Use subdirectories under this subproject to organize the tests. We may share some code later between subprojects (e.g., we might test the overall effect of optimizing syntax quoting an empty vector on the uberjar) but for now, just keep it in the "nil" subproject. Have the git patch file at the top-level of each subproject and add a shared script at the subproject level to construct the uberjar optimized for nil (by cloning Clojure at the specified commit and applying the patch). This will be used by both the uberjar and if-not experiments. Remember to always strip the nondeterminism of jars and then check them against a checksum that you yourself have calculated. Always test and iterate on scripts you create to ensure they run as expected.

Copilot AI and others added 2 commits October 7, 2025 20:24
- Create syntax-quote-optimization/ top-level directory
- Add nil-optimization subproject with:
  - nil-optimization.patch (applies to Clojure 1.12.3)
  - build-optimized-uberjar.sh (shared build script)
  - experiments/uberjar-comparison/
  - experiments/if-not-macro/
- Update all scripts to use shared build script
- Add README.adoc files documenting structure
- Remove old experiments/ directory

Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 7, 2025

@copilot there is a problem. The tests were being run under the optimize-syntax-quote branch, which contains all the syntax-quote optimizations. We need to run the tests under the minimal changes of...

Reorganization complete in commits 9489d3d and above.

Changes implemented:

  1. Git patch created: syntax-quote-optimization/nil-optimization/nil-optimization.patch

    • Applies cleanly to e6393a4 (Clojure 1.12.3 release)
    • Single line change: adds || form == null to LispReader.java
  2. Shared build script: build-optimized-uberjar.sh

    • Clones official Clojure at e6393a4
    • Applies patch
    • Builds uberjar
    • Strips nondeterminism and computes SHA256
    • Tested successfully (SHA256: 99a80942...)
  3. New directory structure:

syntax-quote-optimization/
├── README.adoc (project overview)
└── nil-optimization/
    ├── nil-optimization.patch
    ├── build-optimized-uberjar.sh
    ├── README.adoc (subproject docs)
    └── experiments/
        ├── uberjar-comparison/  (overall JAR impact)
        └── if-not-macro/        (focused if-not analysis)
  1. All scripts updated: Now use shared builder instead of building from fork

The patch is version-controlled (force-added despite .gitignore) and ready for Clojure contribution process.

Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
@frenchy64
Copy link
Owner

@copilot great work. Please move/remove the changes we're no longer using in the branch. For example, move doc/optimize-syntax-quote.md into our ‎syntax-quote-optimization directory (which we'll almost treat as our repo root, other than the Actions files), and remove the changes to src/jvm/clojure/lang/LispReader.java in this branch.

Please go read https://clojure.atlassian.net/browse/CLJ-1506. In the planning documents, please mention this ticket and talk about its relevance (it actually proposes most of the simple optimizations we want to test, like syntax-quoted booleans and nil). Also please read https://clojure.atlassian.net/browse/CLJ-2908 and followed any related links in the description of the ticket. This is the overarching ticket for this work, you should mention this fact in the planning documents. When planning this project, the Clojure maintainers and I were concerned that CLJ-2908 was much to big and we needed to split it up into smaller tickets to make more persuasive cases for the optimizations. We may end up repurposing CLJ-1506 for this. This is useful context for the description of this project in this branch so include something about that.

- Moved doc/optimize-syntax-quote.md to syntax-quote-optimization/
- Reverted src/jvm/clojure/lang/LispReader.java to base (no changes in branch)
- Updated planning documents to reference CLJ-2908 and CLJ-1506
- Added context about splitting large ticket into smaller experiments
- Documented that CLJ-1506 may be repurposed for initial optimizations

Co-authored-by: frenchy64 <287396+frenchy64@users.noreply.github.com>
Copy link
Author

Copilot AI commented Oct 7, 2025

@copilot great work. Please move/remove the changes we're no longer using in the branch. For example, move doc/optimize-syntax-quote.md into our ‎syntax-quote-optimization directory (which we'll...

Changes complete in commit above:

  1. Moved optimize-syntax-quote.md: doc/optimize-syntax-quote.mdsyntax-quote-optimization/optimize-syntax-quote.md

  2. Reverted LispReader.java: Restored to base commit (e6393a4) - no source modifications remain in this branch

  3. Updated planning documents with JIRA context:

    • Added references to CLJ-2908 (overarching optimization ticket)
    • Documented CLJ-1506 (specific optimizations: nil, booleans, empty collections)
    • Explained that CLJ-2908 was too broad and needed splitting
    • Noted that CLJ-1506 may be repurposed for our work
    • Added motivation section explaining why optimize syntax-quote

Both README.adoc files now reference the relevant tickets and explain the project's relationship to ongoing Clojure development discussions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • clojure.atlassian.net
    • Triggering command: curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Focus nil optimization analysis on if-not macro with reproducible verification scripts Syntax-quote optimization experiments with git patches and reproducible verification Oct 7, 2025
@frenchy64 frenchy64 closed this Oct 7, 2025
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