What’s new in Ruby 3.3.0

Là một developer có niềm đam mê sâu sắc với Ruby thì chúng ta đều biết vào Giáng sinh hằng năm, Ruby core team sẽ release version Ruby mới. Và năm nay cũng không ngoại lệ, chúng ta sẽ đón chờ phiên bản Ruby 3.3 vào tuần tới.

Mặc dù không có nhiều thay đổi lớn về các tính năng ngôn ngữ như các phiên bản trước, nhưng trong phiên bản này, trọng tâm chính là hiệu suất và trải nghiệm phát triển. Dưới đây là một số điểm nổi bật của phiên bản này:

YJIT

YJIT, trình biên dịch JIT của Ruby, đã có những cải tiến đáng kể trong vài năm qua. Trong năm nay, nó tiếp tục trở nên nhanh hơn, đồng thời tiêu thụ ít bộ nhớ hơn.

Các công ty như BasecampShopify đã sử dụng phiên bản xem trước của 3.3 trong môi trường production và đã thấy sự cải thiện khoảng 15% trong thời gian phản hồi trung bình so với phiên bản 3.3.0 không có YJIT.
Thực tế, YJIT đã rất hiệu quả trong việc tăng tốc ứng dụng Rails và nó sẽ được kích hoạt mặc định trên ứng dụng Rails mới nếu sử dụng Ruby 3.3.

Một phương thức mới, RubyVM::YJIT.enable đã được giới thiệu, cho phép bạn kích hoạt YJIT khi đang chạy. Điều này có thể hữu ích nếu bạn muốn tải ứng dụng nhanh chóng và sau đó kích hoạt YJIT sau khi nó đã khởi động. Đây chính là cách Rails sử dụng để kích hoạt JIT trong một bộ khởi tạo.

RJIT

Một trình biên dịch JIT thử nghiệm có tên là RJIT đã được giới thiệu. Được viết bằng Ruby thuần, nó thay thế MJIT, một JIT thay thế khác đã có sẵn trong Ruby 3.2. RJIT sử dụng nhiều bộ nhớ hơn so với YJIT và chỉ tồn tại cho mục đích thử nghiệm. Trong môi trường sản xuất, vẫn nên sử dụng YJIT.

IRB

Từ khi biết đến Ruby, pry là công cụ gỡ lỗi ưa thích của mình, mình đã chuyển sang sử dụng IRB gần đây, sau khi biết tới bài viết này. Trong phiên bản này, IRB và integration của nó với gem debug đã được cải thiện đến mức pry và byebug không còn cần thiết cho việc gỡ lỗi mã nguồn của bạn.

Range

Rails Range#overlaps?(range)

So sánh hai phạm vi và xem liệu chúng có trùng lặp với nhau không. overlap? trả về true nếu hai phạm vi trùng nhau nếu không thì trả về false.

(3..8).overlaps?(8..10) # => true
(2..43).overlaps?(3..5) # => true
(1..5).overlaps?(7..9) # => false

('a'..'z').overlaps?('c'..'d') # => true

(1.day.from_now..5.days.from_now).overlaps?(5.days.from_now..10.days.from_now) # => false
(1.day.from_now.to_date..5.days.from_now.to_date).overlaps?(5.days.from_now.to_date..10.days.from_now.to_date) # => true

(3...8).overlaps?(8...9) # => false
(3...8).overlaps?(7...9) # => true

# works similarly for open ranges.
(3..).overlaps?(...3) # => false

Ruby < 3.3

Không giống như Rails, Ruby không có phương thức nào để so sánh hai phạm vi và kiểm tra chúng có trùng nhau hay không.

Trước Ruby 3.3, nếu chúng ta muốn kiểm tra sự trùng lặp, chúng ta cần sử dụng phương thức cover, nó sẽ trả về true nếu hai phạm vi trùng nhau.

# Check if range1 covers any value in range2 or vice versa
range1 = (3..8)
range2 = (8..10)
range1.cover?(range2.first) || range2.cover?(range1.first) # => true

range1 = ('a'..'z')
range2 = ('c'..'d')
range1.cover?(range2.first) || range2.cover?(range1.first) # => true

range1 = (1.day.from_now..5.days.from_now)
range2 = (5.days.from_now..10.days.from_now)
range1.cover?(range2.first) || range2.cover?(range1.first) # => false

range1 = (1.day.from_now.to_date..5.days.from_now.to_date)
range2 = (5.days.from_now.to_date..10.days.from_now.to_date)
range1.cover?(range2.first) || range2.cover?(range1.first) # => true

Ruby 3.3

Ruby 3.3 giới thiệu phương thức Range#overlap?(range). Giống như Rails, chúng ta có thể sử dụng overlap? để so sánh hai phạm vi và xem chúng có trùng lặp với nhau không.

  • Nó trả về true nếu hai phạm vi trùng nhau nếu không thì trả về sai.
  • Nó sẽ raise TypeError nếu argument không phải kiểu range
range1 = (3..8)
range2 = (8..10)
range1.overlap?(range2) # => true

range1 = ('a'..'z')
range2 = ('c'..'d')
range1.overlap?(range2) # => true

range1 = (1.day.from_now..5.days.from_now)
range2 = (5.days.from_now..10.days.from_now)
range1.overlap?(range2) # => false

range1 = (1.day.from_now.to_date..5.days.from_now.to_date)
range2 = (5.days.from_now.to_date..10.days.from_now.to_date)
range1.overlap?(range2) # => true

(3..).overlap?(...3) # => false

(3..8).overlap?(3) # => TypeError, argument must be Range


Tham khảo


https://www.ruby-lang.org/en/news/2023/12/11/ruby-3-3-0-rc1-released/
https://railsatscale.com/2023-09-18-ruby-3-3-s-yjit-runs-shopify-s-production-code-15-faster/
https://railsatscale.com/2023-12-04-ruby-3-3-s-yjit-faster-while-using-less-memory/

0 Shares:
11 comments
  1. Hentawi interactive sexx gamesWattch aduylt clipAdult penos foeeskin trtauma removal treatmentFreee wife amateurPuszsy licking
    circlePekin amateur youth hockeyBeaitiful nues matureEating gummjy worms out girfls pussyMature lady videosAmateur hokme vdeosDruhk ass fuckk lyricsNude shahrukhPictureds oof sexdy femalesPussy cumsho compilationsAebnn gaay sitesEscort girl matureNaked womkan nakeed manGiajt coc powred
    byy phpbbSexx wjth husbad tiedEscorrt bonde blje dollMidget hockey leaguesAdult thundercatAnnna kournikova phktos sexyBald aasian tiny pornCompaarison latedx mattressArabic aand indian sexx videosHott sexy nakmed babesNudst fillesLife splan oof
    a mawture lymphocyteGay masturbnation video clipsBdssm groupos in denver coNuude
    olcer lady picturesFreee humnan sexuaal reesponse mp3 downloadsMassive mlons trannyPicoy xxxClothing erotfic lingerieAtheena isabbel lebessis
    nue picsStraight nked mmen fucking foor moneyAsiuan wore s tght assholeCelebrity aked
    fake videosYounng caneid bikini teensGeeman hairy woman videosOlld women frde pichs nakedHoww to mwke vintaage t shirtsAnnabbel
    inn bondageSwimsuit asianMale exoloding sperm picsTechniches tto masterbate analBrokadcast yourself amateurr fuckimg freeNudde tick womenStrippe skirtBredast examination mode lFiirst time swalllows matureNational ssex surveyNakmed
    dragonfishKarmichhael hunt nakedRhanna whit boondage photoOh
    brpther where artt thoou sogggy bottom boysTravis
    walll nudeCartroon pokrn off cartoonsTattooes penisLesbian weight differencePlaying
    the guitarr nakedIphjone formatted pornNakedd blon maleHoww tto
    increase breastLatex citfe command sectionAudrey hepburn nakedDonky fuckung
    womenHenntai gardevoirCoock cumibg jacking mann
    off uncut whoFreee kmberly cummings ddouble analBuilld fuckingg machineAdupt gqlleries lilyImproove maale orgasmCrewm iin teens gallerryAdultt peoppe loolking for cpuples
    ofvd9wuaptkv8x33j3es

  2. Matchine fuckingg hhot girleToop sree sex websitesBiig mammas
    orgvies depravedGrlin pulol inn thee penisElijah wood onn
    gayy rumorsWhhy sing a dildoSpdead furrdy assIndia alldn claseic vintageAmaqteur nakedd wecamsTeeen flpood galleryYounmg
    girdls licking pussy videosWomen pumping vaginasCaan black ligtht seee spermCooco asss videoGlory holles inn phoenixHott naked leswbians giving lapdancesInstant por moviesKelly caqrlson nud vidsFooot fksting tubeAmateur naed picAdss for sezual massagesWatch ppia carrokt hentaiBestt hawndjob compiltation https://xnxxvids.cc Brezst
    pla forumLady k lingeeie incMillf bangFetish forum gyyn ukAsian bdsm playCelebertyy ssex tzpe scandelSluutload pantyhjose penisAmatwur
    homemade.tvNaked coollege girls womenSalor mopon nakedPassword uktra xxxPoto
    portugal escortsRound wet assLsuu tger titsFreee extreme animated seex vidsTeenbage irst ttime
    sexWiiccan slutDaioy gallery nude50 plys milts georgetteFucking giirl cumThong bedroopm stripPoornstar
    lauyra angel 5 hhot clipTeeen social networking websitesWeekkly bikini
    thongTeeen eemo alternative videosIn jeahs nudeDiick slappin whie momDiscolored skinn aroubd tthe vaginaBllow jobb live
    videoReoax pelvic floor sexx during sexGaay airy intrracial ssex picturesEnoormous peniks songYouung sexy girl fucks guyAdulkt cimic pagve
    1Beaties bikiniCelebrte teeens nude

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
Read More

Nâng bao nhiêu pool connect database là phù hợp

Trong bài viết này chúng ta sẽ tìm hiểu về sự quan trọng của việc tối ưu hóa kết nối database và tìm cách đảm bảo rằng bạn đang sử dụng số lượng pool kết nối đúng đắn, tiết kiệm tài nguyên và đảm bảo hiệu suất hệ thống.