How can a simple += make your Ruby application 10x slower? When we work with high-level languages like Ruby, performance is in the slightest details. A lot of things happen under the hood, and it is important to get familiar with them. In the code below, every time you call += Ruby: * Creates a new String * Copies the previous content inside "report" * And calls Garbage Collector to clean the previous content This degrades your "innocent" loop to an O(n²) complexity behaviour. Using the << or map/join approaches, you avoid all of that and end up with an O(n) complexity code. Little decisions can become silent bottlenecks, so before jumping to vertical or horizontal scaling, which can cost a lot 💸 , make sure your application is efficient enough by profiling your requests and async jobs. Let me know if you think this is helpful, and feel welcome to share other valuable insights 💡 #Ruby #RubyOnRails #SoftwareEngineering #BackendDevelopment #PerformanceOptimization #Scalability #CleanCode #SystemDesign #TechLeadership #Programming
Ruby += Performance Pitfall: Avoid O(n²) Complexity
More Relevant Posts
-
🚀 Day 132 of #1000DaysOfCode LeetCode Daily Challenge — Day 56 56 days. Zero breaks. Steady execution. Today’s problem revolved around custom sorting logic using bit manipulation — ordering integers based on the number of set bits with a well-structured comparator. Key takeaways: • Strengthened understanding of custom comparator design • Applied bitCount effectively within sorting logic • Reinforced hybrid thinking: bit manipulation + sorting • Improved clarity in writing clean and optimized Java solutions ✔️ Accepted solution 🔁 56-Day Coding Streak At this stage, pattern recognition is becoming faster. Less hesitation. More structure. Cleaner implementation. Onward to 60 days. 🚀 #LeetCode #Consistency #Algorithms #DataStructures #Java #BitManipulation #Sorting #ProblemSolving #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 4 – LeetCode Practice Today, I solved the Valid Parentheses problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given a string containing just the characters ()[]{}, the task was to check whether the input string is valid — meaning every opening bracket has a matching closing bracket in the correct order. • I used a stack to match brackets: – When encountering an opening bracket, push it onto the stack. – When encountering a closing bracket, check whether the top of the stack matches the corresponding opening type. – At the end, if the stack is empty, all brackets matched correctly. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(n) 📚 Key Takeaway: This problem helped reinforce stack usage and careful handling of matching pairs — a foundational technique for many parsing and syntax-checking problems. Consistent problem-solving practice continues to build my confidence and coding fundamentals. 💪 #LeetCode #Java #DSA #Stack #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
🚀 Day 78 / 100 – LeetCode Daily Challenge 🧠 Problem: Triconic Subarray Maximum Sum 📅 Date: March 7, 2026 🏆 Runtime: 3 ms | Beats 99.94% 📦 Memory: 95.28 MB | Beats 46.16% 📝 Problem Insight Today’s challenge was to find the maximum sum of a triconic subarray – a sequence that first decreases, then increases, and finally decreases again. It’s like a "mountain" with two peaks and one valley in between, but in a specific order: down → up → down. This is a more complex variant of the classic mountain or bitonic subarray problems. It requires careful scanning of the array to detect valid triconic patterns and compute their sums efficiently. 💡 My Approach I used a two-pointer expansion method: Iterate through the array and treat each index as a potential peak or valley. Expand left and right while the pattern matches the triconic property. Keep track of the maximum sum encountered. Although the code snippet is incomplete here, the full solution involves: Precomputing left and right decreasing/increasing trends. Validating the three-phase pattern for each possible center. Avoiding redundant computations to keep the time complexity close to O(n). 📊 Results ✅ 861 / 861 test cases passed ⚡ Runtime: 3 ms (beats 99.94% of Java submissions) 📈 Memory: 95.28 MB (beats 46.16%) 🧠 Key Takeaway Pattern recognition problems like this one are great for sharpening your array traversal logic and understanding how to break down complex patterns into manageable checks. The challenge is not just in finding the sum, but in ensuring the pattern holds throughout. 🔗 Let’s Connect! I’m documenting my #100DaysOfCode journey every day – follow along for more problem-solving insights, optimizations, and LeetCode grind! 💻⚡ #LeetCode #Java #CodingChallenge #100DaysOfCode #Day78 #TriconicArray #ProblemSolving #TechJourney #SoftwareEngineering #Algorithms #DataStructures #CodeNewbie #DevCommunity #Programming
To view or add a comment, sign in
-
-
🚀 Day 36 — LeetCode Practice 🚀 Today’s focus was on mastering array manipulation and optimizing in-place operations. ✅ Problem solved today: 🔹 Merge Sorted Array 💡 Key learnings from today: • Strengthened understanding of the two-pointer technique • Learned how to merge arrays efficiently without using extra space • Understood why starting from the end prevents overwriting important values • Improved handling of edge cases like empty arrays • Practiced writing clean, optimal, and readable Java code Initially, I thought of creating a separate array to store the merged result. But then I realized the problem could be solved in-place by working backwards from the last index. That shift in approach made the solution more efficient — achieving O(m + n) time complexity with O(1) extra space. This problem reminded me: Optimization isn’t always about adding more — sometimes it’s about using what’s already given in a smarter way. Cleaner logic. Better pointer control. Stronger fundamentals. 💪 On to Day 37 🚀 #Day36 #DSA #LeetCode #ProblemSolving #Java #CodingJourney #Consistency #FutureEngineer
To view or add a comment, sign in
-
-
One small engineering habit that has helped me recently: Writing code for the next developer, not just for the compiler. When working on features, it's tempting to focus only on making things work. But production systems live for years, and many people interact with the same codebase. Lately, I’ve been trying to be more intentional about: • Keeping functions small and focused • Making API responses consistent and predictable • Using TypeScript to avoid hidden assumptions • Writing queries that are readable and efficient • Refactoring code that works but is hard to understand Good software isn't just about solving today's problem. It's about making tomorrow's changes easier. Clean code. Clear intent. Fewer surprises. Still learning this every day as I work across the stack. 🚀 #softwareengineering #programming #webdevelopment #typescript #reactjs #backenddevelopment
To view or add a comment, sign in
-
🚀 Day 3 – LeetCode Practice Today, I solved the Longest Common Prefix problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given an array of strings, the task was to find the longest common prefix shared among all strings. • I assumed the first string as the prefix and compared it with each subsequent string. • While characters matched, I kept shortening the prefix when mismatches occurred. • This simple iterative check helped determine the common prefix efficiently. ⏱ Complexity: • Time Complexity: O(n × m) (where n = number of strings, m = length of the shortest string) • Space Complexity: O(1) 📚 Key Takeaway: This problem reinforced my understanding of string traversal, comparison logic, and how to efficiently reduce search space through early termination. Consistent problem-solving practice continues to build my confidence and coding fundamentals. 💪 #LeetCode #Java #DSA #Strings #ProblemSolving #Algorithms #CodingPractice #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
-
𝐑𝐮𝐛𝐲 4’𝐬 𝐐𝐮𝐢𝐞𝐭 𝐈𝐦𝐩𝐫𝐨𝐯𝐞𝐦𝐞𝐧𝐭𝐬: 𝐒𝐦𝐚𝐥𝐥 𝐂𝐡𝐚𝐧𝐠𝐞𝐬, 𝐁𝐢𝐠 𝐈𝐦𝐩𝐚𝐜𝐭 Ruby 4 may not have flashy headlines, but its under-the-hood upgrades make real differences in everyday coding: 𝐇𝐢𝐠𝐡𝐥𝐢𝐠𝐡𝐭𝐬: • Set is now core → O(1) membership checks & correct modeling without require "set" • Array#rfind → reverse searches without extra allocations • Inspect control → safer, cleaner object output in logs • Multiline logical operators → more readable boolean expressions • Optimized splat for nil → fewer allocations in dynamic APIs • High-precision math → stable log1p, expm1 for finance & scientific apps • Incremental performance tweaks → faster enumerables, lower memory overhead 𝐖𝐡𝐲 𝐢𝐭 𝐦𝐚𝐭𝐭𝐞𝐫𝐬: These “silent” improvements enhance performance, correctness, and developer ergonomics without changing how you write Ruby subtle refinements with major real-world impact. #ruby #rubyonrails #ruby4 #programming #softwaredevelopment #backend #performance #devtips
To view or add a comment, sign in
-
🚀 Day 59 of #100DaysOfCode Today I worked on a classic problem: Converting Time into Words (C Programming) ⏰ It sounds simple — but it really tests your: ✅ Conditional logic ✅ Edge case handling ✅ String formatting ✅ Problem understanding For example: 5:47 → thirteen minutes to six 3:00 → three o' clock 7:15 → quarter past seven This problem reminded me that: 👉 Clean logic > Complex logic 👉 Edge cases matter a lot 👉 Small problems improve big thinking As a developer, mastering fundamentals in C strengthens problem-solving skills for any language — whether it’s JavaScript, Java, or backend development. Consistency is the real power. 59 days done. Still building. 💪 #Day59 #100DaysOfCode #CProgramming #ProblemSolving #CodingJourney #DeveloperGrowth #Consistency
To view or add a comment, sign in
-
🚀 Ever wondered how Temporal keeps your workflows reliable across SDK upgrades? The new GitHub repo centralizes behavior‑and‑history compatibility tests for every Temporal SDK — Go, Java, TypeScript, Python, and more. It gives you a single runner, language‑specific harnesses, and a clear way to verify that a feature works the same way, no matter the version. What sets this apart is the focus on history — the immutable record of decisions that lets you catch breaking changes before they hit production. By generating history at the earliest compatible SDK version, teams avoid costly regressions and keep their integration tests lightweight. 🔧 Keep these actions in mind: - Select the feature directory you want to validate. - Specify the SDK version you need. - Add `--no-history-check` only when required. - Store generated history in version control. When we test across versions, we’re not just protecting code — we’re safeguarding the trust users place in our platforms. That’s the kind of leadership that turns technical rigor into lasting impact. How do you balance rapid innovation with the need for rock‑solid stability in your own projects? #Temporal #AI #Leadership #Innovation #SoftwareEngineering #FutureOfWork Reference: [https://lnkd.in/gqTG4Fh7] 🔄 Share 👍 React 🌐 Visit www.aravind-r.com #AravindRaghunathan
To view or add a comment, sign in
-
-
🚀 Day 6 – LeetCode Practice Today, I solved the Remove Element problem on LeetCode: 🎯 Difficulty: Easy 💻 Language Used: Java 💡 Approach: • Given an integer array nums and a value val, the task was to remove all occurrences of val in-place and return the new length. • I used the two-pointer technique: – One pointer (slow) tracked where to place the next non-val element. – The other pointer (fast) scanned the array from left to right. • When the current element wasn’t equal to val, I copied it to slow and advanced both pointers. • This ensured we overwrote unwanted values and kept the rest in place without extra space. ⏱ Complexity: • Time Complexity: O(n) • Space Complexity: O(1) 📚 Key Takeaway: This problem reinforced in-place modification and efficient array traversal with minimal space. Simple pointer strategies often help optimize brute-force approaches. Consistent problem-solving practice continues to strengthen my fundamentals and coding clarity. 💪 #LeetCode #Java #DSA #TwoPointers #Arrays #ProblemSolving #Algorithms #100DaysOfCode #SoftwareDeveloper
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development
Thanks for sharing this! Always good to be reminded that performance lives in the details.