Skip to content

Conversation

@adcondev
Copy link
Owner

Fixed a race condition in pkg/emulator/fonts.go where scaledFaces map was accessed without synchronization.
Added sync.RWMutex to FontManager struct and protected all accesses to scaledFaces.
Implemented double-checked locking in GetOrCreateScaledFace for thread-safe cache population.
Ensured font.Face resources are closed when evicted or discarded to prevent leaks.
Added a regression test TestScaledFacesRace.


PR created automatically by Jules for task 11490920620544650492 started by @adcondev

Protected `scaledFaces` map in `pkg/emulator/fonts.go` with `sync.RWMutex` to prevent data races when accessed from multiple goroutines.
Implemented double-checked locking in `GetOrCreateScaledFace` and ensured proper resource cleanup by calling `Close()` on speculatively created font faces.
Also updated `ClearScaledFaceCache` to close existing font faces before clearing the map.
Added `pkg/emulator/fonts_test.go` with `TestScaledFacesRace` to verify the fix and prevent regression.

Co-authored-by: adcondev <38170282+adcondev@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings February 12, 2026 16:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot wasn't able to review any files in this pull request.


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

@github-actions
Copy link
Contributor

👋 Thanks for opening this PR, @adcondev!

Here's what will happen next:

  • 🤖 Automated checks will run
  • 🏷️ Labels will be added automatically
  • 👀 A maintainer will review your changes

Please make sure:

  • ✅ All tests pass
  • 📝 The PR title follows conventional commits
  • 📋 The PR template is filled out completely

@github-actions
Copy link
Contributor

github-actions bot commented Feb 12, 2026

⚡ Benchmark Results

📈 Performance Comparison

📊 Click to expand detailed results

Current Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3117 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3654206	       327.8 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  405218	      2707 ns/op	    1809 B/op	      25 allocs/op
BenchmarkToJSON-4         	  532221	      2059 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  518594	      2300 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   94836	     12634 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  426663	      2717 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  276552	      4161 ns/op	     944 B/op	      21 allocs/op
BenchmarkTextCommandParsing-4       	  528488	      2105 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  231340	      4783 ns/op	    1000 B/op	      29 allocs/op
BenchmarkParseHexString-4           	 8838931	       135.4 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6696802	       177.7 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	362982424	         3.241 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	31875718	        38.24 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14612720	        82.62 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  501556	      2384 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  141553	      8442 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     620	   1863474 ns/op	 3469936 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     326	   3642526 ns/op	 5481085 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     140	   8483722 ns/op	 5235274 B/op	  230723 allocs/op

Base Branch Results

BenchmarkNewDocument-4    	1000000000	         0.3120 ns/op	       0 B/op	       0 allocs/op
BenchmarkBuildSimple-4    	 3624811	       331.4 ns/op	     240 B/op	       4 allocs/op
BenchmarkBuildComplex-4   	  418526	      2704 ns/op	    1809 B/op	      25 allocs/op
BenchmarkToJSON-4         	  532363	      2068 ns/op	     592 B/op	       3 allocs/op
BenchmarkParseDocument_Minimal-4    	  502388	      2308 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Receipt-4    	   95671	     12720 ns/op	    2392 B/op	      34 allocs/op
BenchmarkCommandUnmarshal_Text-4    	  429228	      2676 ns/op	     568 B/op	      19 allocs/op
BenchmarkCommandUnmarshal_Table-4   	  278497	      4143 ns/op	     944 B/op	      21 allocs/op
BenchmarkTextCommandParsing-4       	  539864	      2101 ns/op	     544 B/op	      16 allocs/op
BenchmarkTableCommandParsing-4      	  246220	      4786 ns/op	    1000 B/op	      29 allocs/op
BenchmarkParseHexString-4           	 8797804	       135.3 ns/op	      48 B/op	       2 allocs/op
BenchmarkCleanHexString-4           	 6661963	       178.0 ns/op	      64 B/op	       2 allocs/op
BenchmarkContainsSequence-4         	368543936	         3.311 ns/op	       0 B/op	       0 allocs/op
BenchmarkCheckCriticalCommands-4    	36582168	        38.96 ns/op	       0 B/op	       0 allocs/op
BenchmarkDocument_Validate-4       	14491092	        83.19 ns/op	       0 B/op	       0 allocs/op
BenchmarkParseDocument_Simple-4    	  502436	      2381 ns/op	     568 B/op	      14 allocs/op
BenchmarkParseDocument_Complex-4   	  138806	      8434 ns/op	    1352 B/op	      26 allocs/op
BenchmarkPrintImage_Small-4             	     586	   1915481 ns/op	 3469938 B/op	      24 allocs/op
BenchmarkPrintImage_Medium-4            	     328	   3669982 ns/op	 5481087 B/op	      24 allocs/op
BenchmarkPrintImage_ThermalPreview-4    	     140	   8658248 ns/op	 5235270 B/op	  230723 allocs/op

💡 Note: Use benchstat for statistical comparison

🎯 Summary

  • Total Benchmarks: 32
  • Average Speed: 2578131 ns/op
  • Average Memory: 2396933 B/op
  • Average Allocations: 41093 allocs/op

Protected `scaledFaces` map in `pkg/emulator/fonts.go` with `sync.RWMutex` to prevent data races when accessed from multiple goroutines.
Implemented double-checked locking in `GetOrCreateScaledFace` and ensured proper resource cleanup by calling `Close()` on speculatively created font faces.
Also updated `ClearScaledFaceCache` to close existing font faces before clearing the map.
Added `pkg/emulator/fonts_test.go` with `TestScaledFacesRace` to verify the fix and prevent regression.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
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.

1 participant