Skip to content

PG::Result: Initialize all on-demand values before freeze#674

Merged
larskanis merged 5 commits into
ged:masterfrom
larskanis:init-result-cache
Oct 6, 2025
Merged

PG::Result: Initialize all on-demand values before freeze#674
larskanis merged 5 commits into
ged:masterfrom
larskanis:init-result-cache

Conversation

@larskanis

Copy link
Copy Markdown
Collaborator

Multiple Ractor instances could otherwise initialize them simultanly, leading to data races.

@larskanis larskanis changed the title PG::Result: Initialize all caches before freeze PG::Result: Initialize all on-demand values before freeze Sep 27, 2025
... and do not use tuple_hash.
Multiple Ractor instances could otherwise initialize them simultanly, leading to data races.
It results in the same performance, but is simpler.
To allocate the necessary memory from the start.
The PG::Result spec fails with pg-1.6.2 like so:

  1) PG::Result should be distributable to Ractors
     Failure/Error: expect( arr ).to eq( (1..100).to_a.flat_map{|a| [{"f" => a.to_s}, {"f" => a.to_s}] } )

       expected: [{"f" => "1"}, {"f" => "1"}, {"f" => "2"}, {"f" => "2"}, {"f" => "3"}, {"f" => "3"}, {"f" => "4"}, {"...> "97"}, {"f" => "98"}, {"f" => "98"}, {"f" => "99"}, {"f" => "99"}, {"f" => "100"}, {"f" => "100"}]
            got: [{"f" => "1"}, {"f" => "1"}, {"f" => "2"}, {"f" => "2"}, {"f" => "3"}, {"f" => "3"}, {"f" => "4"}, {"...> "97"}, {"f" => "98"}, {"f" => "98"}, {"f" => "99"}, {"f" => "99"}, {"f" => "100"}, {"f" => "100"}]

       (compared using ==)

       Diff:

       @@ -165,9 +165,9 @@
         {"f" => "83"},
         {"f" => "83"},
         {"f" => "84"},
       - {"f" => "84"},
         {"f" => "85"},
         {"f" => "85"},
       + {"f" => "85"},
         {"f" => "86"},
         {"f" => "86"},
         {"f" => "87"},
       @@ -179,7 +179,7 @@
         {"f" => "90"},
         {"f" => "90"},
         {"f" => "91"},
       - {"f" => "91"},
       + {"f" => "92"},
         {"f" => "92"},
         {"f" => "92"},
         {"f" => "93"},

      ./spec/pg/result_spec.rb:61:in 'block (2 levels) in <top (required)>'
      ./spec/helpers.rb:64:in 'block in PG::TestingHelpers.included'
@larskanis larskanis merged commit a91365b into ged:master Oct 6, 2025
33 of 34 checks passed
@larskanis larskanis deleted the init-result-cache branch October 6, 2025 07:45
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.

1 participant